Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Add update support.

  • Loading branch information...
commit 5f881e9c25044e4f5092dcf943b82b5c8d4574eb 1 parent bca9b29
@dr4g0nnn authored
Showing with 8 additions and 4 deletions.
  1. +8 −4 lib/gist.rb
View
12 lib/gist.rb
@@ -46,6 +46,7 @@ def execute(*args)
gist_extension = defaults["extension"]
browse_enabled = defaults["browse"]
description = nil
+ update_to = nil
opts = OptionParser.new do |opts|
opts.banner = "Usage: gist [options] [filename or stdin] [filename] ...\n" +
@@ -63,6 +64,9 @@ def execute(*args)
opts.on('-d','--description DESCRIPTION', 'Set description of the new gist') do |d|
description = d
end
+ opts.on('-u', '--update GIST_ID', 'Update an already existing gist') do |i|
+ update_to = i
+ end
opts.on('-o','--[no-]open', 'Open gist in browser') do |o|
browse_enabled = o
@@ -113,7 +117,7 @@ def execute(*args)
files = [{:input => input, :extension => gist_extension}]
end
- url = write(files, private_gist, description)
+ url = write(files, private_gist, description, update_to)
browse(url) if browse_enabled
puts copy(url)
rescue => e
@@ -123,8 +127,8 @@ def execute(*args)
end
# Create a gist on gist.github.com
- def write(files, private_gist = false, description = nil)
- url = URI.parse(CREATE_URL)
+ def write(files, private_gist = false, description = nil, update_to=nil)
+ url = URI.parse(CREATE_URL + (update_to ? "/#{update_to}" : ""))
if PROXY_HOST
proxy = Net::HTTP::Proxy(PROXY_HOST, PROXY_PORT)
@@ -147,7 +151,7 @@ def write(files, private_gist = false, description = nil)
response = http.start{|h| h.request(req) }
case response
- when Net::HTTPCreated
+ when Net::HTTPCreated, Net::HTTPOK
JSON.parse(response.body)['html_url']
else
puts "Creating gist failed: #{response.code} #{response.message}"
Please sign in to comment.
Something went wrong with that request. Please try again.