Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Added an option to set description

  • Loading branch information...
commit 58d091bc5a148c5abcbf3ff445f534a21c8e63c2 1 parent a116fb0
sam7wx authored
Showing with 10 additions and 4 deletions.
  1. +10 −4 lib/gist.rb
View
14 lib/gist.rb
@@ -42,6 +42,7 @@ def execute(*args)
gist_filename = nil
gist_extension = defaults["extension"]
browse_enabled = defaults["browse"]
+ description = nil
opts = OptionParser.new do |opts|
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -56,6 +57,10 @@ def execute(*args)
gist_extension = '.' + extension
end
+ opts.on('-d','--description DESCRIPTION', 'Set description of the new gist') do |d|
+ description = d
+ end
+
opts.on('-o','--[no-]open', 'Open gist in browser') do |o|
browse_enabled = o
end
@@ -104,7 +109,7 @@ def execute(*args)
files = [{:input => input, :extension => gist_extension}]
end
- url = write(files, private_gist)
+ url = write(files, private_gist, description)
browse(url) if browse_enabled
puts copy(url)
rescue => e
@@ -114,7 +119,7 @@ def execute(*args)
end
# Create a gist on gist.github.com
- def write(files, private_gist = false)
+ def write(files, private_gist = false, description = nil)
url = URI.parse(CREATE_URL)
if PROXY_HOST
@@ -129,7 +134,7 @@ def write(files, private_gist = false)
http.ca_file = ca_cert
req = Net::HTTP::Post.new(url.path)
- req.form_data = data(files, private_gist)
+ req.form_data = data(files, private_gist, description)
response = http.start{|h| h.request(req) }
case response
@@ -180,7 +185,7 @@ def copy(content)
private
# Give an array of file information and private boolean, returns
# an appropriate payload for POSTing to gist.github.com
- def data(files, private_gist)
+ def data(files, private_gist, description)
data = {}
files.each do |file|
i = data.size + 1
@@ -188,6 +193,7 @@ def data(files, private_gist)
data["file_name[gistfile#{i}]"] = file[:filename]
data["file_contents[gistfile#{i}]"] = file[:input]
end
+ data.merge!({ 'description' => description }) unless description.nil?
data.merge(private_gist ? { 'action_button' => 'private' } : {}).merge(auth)
end
Please sign in to comment.
Something went wrong with that request. Please try again.