Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP

Loading…

new option to set a description #49

Merged
merged 1 commit into from

2 participants

@ghost

a feature requested as #10

This commit adds a command line option -d (or --description DESCRIPTION) which sets a description of gist.

@indirect indirect merged commit fea7f0a into from
@indirect
Collaborator

looks good, thanks.

@weakish

It seems this feature haven't got documented into the man page.

@ghost

I've sent a pull request to update the man page: #51

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Commits on May 19, 2011
  1. Added an option to set description

    sam7wx authored
This page is out of date. Refresh to see the latest.
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
Something went wrong with that request. Please try again.