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
47
47
or URL with "-u". For this to work, you must be logged in, and have created the
48
48
original gist with the same GitHub account.
49
49
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*
51
55
#{ executable_name } --login
52
56
#{ executable_name } [-l|-r]
53
57
@@ -107,6 +111,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
107
111
108
112
opts . on ( "--no-open" )
109
113
114
+ opts . on ( "--skip-empty" , "Skip gisting empty files" ) do
115
+ options [ :skip_empty ] = true
116
+ end
117
+
110
118
opts . on ( "-P" , "--paste" , "Paste from the clipboard to gist" ) do
111
119
options [ :paste ] = true
112
120
end
@@ -195,7 +203,8 @@ begin
195
203
end
196
204
end
197
205
198
- puts Gist . multi_gist ( files , options )
206
+ output = Gist . multi_gist ( files , options )
207
+ puts output if output
199
208
end
200
209
201
210
rescue Gist ::Error => e
Original file line number Diff line number Diff line change @@ -92,6 +92,7 @@ def gist(content, options = {})
92
92
# @option options [String] :update the URL or id of a gist to update
93
93
# @option options [Boolean] :copy (false) Copy resulting URL to clipboard, if successful.
94
94
# @option options [Boolean] :open (false) Open the resulting URL in a browser.
95
+ # @option options [Boolean] :skip_empty (false) Skip gisting empty files.
95
96
# @option options [Symbol] :output (:all) The type of return value you'd like:
96
97
# :html_url gives a String containing the url to the gist in a browser
97
98
# :short_url gives a String contianing a git.io url that redirects to html_url
@@ -110,10 +111,15 @@ def multi_gist(files, options={})
110
111
json [ :files ] = { }
111
112
112
113
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
115
119
end
116
120
121
+ return if json [ :files ] . empty? && options [ :skip_empty ]
122
+
117
123
existing_gist = options [ :update ] . to_s . split ( "/" ) . last
118
124
if options [ :anonymous ]
119
125
access_token = nil
You can’t perform that action at this time.
0 commit comments