File tree Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Expand file tree Collapse file tree 2 files changed +19
-4
lines changed Original file line number Diff line number Diff line change @@ -47,7 +47,11 @@ Instead of creating a new gist, you can update an existing one by passing its ID
4747or URL with "-u". For this to work, you must be logged in, and have created the
4848original gist with the same GitHub account.
4949
50- Usage: #{ executable_name } [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
50+ If you want to skip empty files, use the --skip-empty flag. If all files are
51+ empty no gist will be created.
52+
53+ Usage: #{ executable_name } [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL]
54+ [--skip-empty] [-P] [-f NAME|-t EXT]* FILE*
5155 #{ executable_name } --login
5256 #{ executable_name } [-l|-r]
5357
@@ -107,6 +111,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
107111
108112 opts . on ( "--no-open" )
109113
114+ opts . on ( "--skip-empty" , "Skip gisting empty files" ) do
115+ options [ :skip_empty ] = true
116+ end
117+
110118 opts . on ( "-P" , "--paste" , "Paste from the clipboard to gist" ) do
111119 options [ :paste ] = true
112120 end
@@ -195,7 +203,8 @@ begin
195203 end
196204 end
197205
198- puts Gist . multi_gist ( files , options )
206+ output = Gist . multi_gist ( files , options )
207+ puts output if output
199208 end
200209
201210rescue Gist ::Error => e
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ def gist(content, options = {})
9292 # @option options [String] :update the URL or id of a gist to update
9393 # @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
9494 # @option options [Boolean] :open (false) Open the resulting URL in a browser.
95+ # @option options [Boolean] :skip_empty (false) Skip gisting empty files.
9596 # @option options [Symbol] :output (:all) The type of return value you'd like:
9697 # :html_url gives a String containing the url to the gist in a browser
9798 # :short_url gives a String contianing a git.io url that redirects to html_url
@@ -110,10 +111,15 @@ def multi_gist(files, options={})
110111 json [ :files ] = { }
111112
112113 files . each_pair do |( name , content ) |
113- raise "Cannot gist empty files" if content . to_s . strip == ""
114- json [ :files ] [ File . basename ( name ) ] = { :content => content }
114+ if content . to_s . strip == ""
115+ raise "Cannot gist empty files" unless options [ :skip_empty ]
116+ else
117+ json [ :files ] [ File . basename ( name ) ] = { :content => content }
118+ end
115119 end
116120
121+ return if json [ :files ] . empty? && options [ :skip_empty ]
122+
117123 existing_gist = options [ :update ] . to_s . split ( "/" ) . last
118124 if options [ :anonymous ]
119125 access_token = nil
You can’t perform that action at this time.
0 commit comments