File tree Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Expand file tree Collapse file tree 2 files changed +33
-0
lines changed Original file line number Diff line number Diff line change @@ -49,6 +49,7 @@ original gist with the same GitHub account.
49
49
50
50
Usage: #{ executable_name } [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P] [-f NAME|-t EXT]* FILE*
51
51
#{ executable_name } --login
52
+ #{ executable_name } [-l|-r]
52
53
53
54
EOS
54
55
@@ -118,6 +119,10 @@ Usage: #{executable_name} [-o|-c|-e] [-p] [-s] [-R] [-d DESC] [-a] [-u URL] [-P]
118
119
options [ :list ] = user
119
120
end
120
121
122
+ opts . on ( "-r" , "--read ID [FILENAME]" , "Read a gist and print out the contents" ) do |id |
123
+ options [ :read ] = id
124
+ end
125
+
121
126
opts . on_tail ( "-h" , "--help" , "Show this message." ) do
122
127
puts opts
123
128
exit
@@ -156,6 +161,12 @@ begin
156
161
exit
157
162
end
158
163
164
+ if options . key? :read
165
+ file_name = ARGV . first
166
+ Gist . read_gist ( options [ :read ] , file_name )
167
+ exit
168
+ end
169
+
159
170
if options [ :paste ]
160
171
puts Gist . gist ( Gist . paste , options )
161
172
else
Original file line number Diff line number Diff line change @@ -201,6 +201,28 @@ def list_all_gists(user = "")
201
201
202
202
end
203
203
204
+ def read_gist ( id , file_name = nil )
205
+ url = "#{ base_path } /gists/#{ id } "
206
+ request = Net ::HTTP ::Get . new ( url )
207
+ response = http ( api_url , request )
208
+
209
+ if response . code == '200'
210
+ body = JSON . parse ( response . body )
211
+ files = body [ "files" ]
212
+
213
+ if file_name
214
+ file = files [ file_name ]
215
+ raise Error , "Gist with id of #{ id } and file #{ file_name } does not exist." unless file
216
+ else
217
+ file = files . values . first
218
+ end
219
+
220
+ puts file [ "content" ]
221
+ else
222
+ raise Error , "Gist with id of #{ id } does not exist."
223
+ end
224
+ end
225
+
204
226
def get_gist_pages ( url )
205
227
206
228
request = Net ::HTTP ::Get . new ( url )
You can’t perform that action at this time.
0 commit comments