jtag 0.1.8 → 0.1.10
Sign up to get free protection for your applications and to get access to all the features.
- data/bin/jtag +113 -27
- data/lib/jtag.rb +1 -0
- data/lib/jtag/version.rb +1 -1
- metadata +18 -8
data/bin/jtag
CHANGED
@@ -93,10 +93,10 @@ desc 'List tags, optionally filter for keywords/regular expressions (OR)'
|
|
93
93
|
long_desc 'This command can be used to find the exact format for a given tag to keep spaces, underscores, capitalization and pluralization consistent'
|
94
94
|
arg_name 'keyword', :multiple
|
95
95
|
command :search do |c|
|
96
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
96
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
97
97
|
c.arg_name 'output_format'
|
98
98
|
c.default_value 'yaml'
|
99
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/i, :type => String
|
99
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/i, :type => String
|
100
100
|
|
101
101
|
c.desc 'Include tag counts'
|
102
102
|
c.arg_name 'counts'
|
@@ -119,7 +119,7 @@ command :search do |c|
|
|
119
119
|
else
|
120
120
|
tags.map! {|tag| tag['name'] }
|
121
121
|
end
|
122
|
-
output_tags(tags,options[:format])
|
122
|
+
output_tags(tags,{ :format => options[:format] })
|
123
123
|
else
|
124
124
|
tags.delete_if {|tag| !tag }
|
125
125
|
if options[:c]
|
@@ -127,18 +127,87 @@ command :search do |c|
|
|
127
127
|
else
|
128
128
|
tags.map! {|tag| tag['name'] }
|
129
129
|
end
|
130
|
-
output_tags(tags,options[:format])
|
130
|
+
output_tags(tags,{ :format => options[:format] })
|
131
131
|
end
|
132
132
|
end
|
133
133
|
end
|
134
134
|
|
135
|
+
desc 'List posts with tag(s)'
|
136
|
+
arg_name 'tags', :multiple
|
137
|
+
command :posts_tagged do |c|
|
138
|
+
c.desc 'Boolean operator for multiple tags (AND/OR/NOT)'
|
139
|
+
c.arg_name 'bool'
|
140
|
+
c.default_value 'OR'
|
141
|
+
c.flag [:b,:bool], :must_match => /(AND|OR|NOT)/i, :type => String
|
142
|
+
|
143
|
+
c.desc 'Format to use when outputting file list: list, json, plist, csv or yaml. Defaults to list.'
|
144
|
+
c.arg_name 'output_format'
|
145
|
+
c.default_value 'list'
|
146
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
147
|
+
|
148
|
+
c.desc 'If output format is list, print without newlines.'
|
149
|
+
c.switch [:print0]
|
150
|
+
|
151
|
+
c.action do |global_options,options,args|
|
152
|
+
bool = options[:bool].upcase
|
153
|
+
files = []
|
154
|
+
tags = []
|
155
|
+
matches = []
|
156
|
+
args.length.times do
|
157
|
+
arg = args.pop
|
158
|
+
if File.exists?(arg)
|
159
|
+
files.push(arg)
|
160
|
+
else
|
161
|
+
exit_now! "No valid filename in arguments" if files.empty?
|
162
|
+
tags.push(arg)
|
163
|
+
end
|
164
|
+
end
|
165
|
+
files.each {|file|
|
166
|
+
if File.exists?(file)
|
167
|
+
post_tags = @jt.post_tags(file)
|
168
|
+
|
169
|
+
if bool == "AND"
|
170
|
+
matched = 0
|
171
|
+
tags.each {|tag|
|
172
|
+
matched += 1 if post_tags.include?(tag)
|
173
|
+
}
|
174
|
+
matches.push(file) if matched == tags.length
|
175
|
+
elsif bool == "NOT"
|
176
|
+
matched = false
|
177
|
+
tags.each {|tag|
|
178
|
+
matched = true if post_tags.include?(tag)
|
179
|
+
}
|
180
|
+
matches.push(file) unless matched
|
181
|
+
else
|
182
|
+
tags.each {|tag|
|
183
|
+
if post_tags.include?(tag)
|
184
|
+
matches.push(file) unless matches.include?(file)
|
185
|
+
end
|
186
|
+
}
|
187
|
+
end
|
188
|
+
else
|
189
|
+
raise "File not found: #{file}"
|
190
|
+
end
|
191
|
+
}
|
192
|
+
|
193
|
+
search_string = tags.join(" #{bool} ")
|
194
|
+
if matches.empty?
|
195
|
+
console_log "No matching files found for #{search_string}"
|
196
|
+
else
|
197
|
+
console_log "(#{search_string})", {:err => true}
|
198
|
+
output_tags(matches, { :format => options[:format], :print0 => options[:print0], :grouping => "files" })
|
199
|
+
end
|
200
|
+
end
|
201
|
+
end
|
202
|
+
|
203
|
+
|
135
204
|
desc 'Show the current tags for posts'
|
136
205
|
arg_name 'filenames', :multiple
|
137
206
|
command :tags do |c|
|
138
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
207
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
139
208
|
c.arg_name 'output_format'
|
140
209
|
c.default_value 'yaml'
|
141
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
210
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
142
211
|
|
143
212
|
c.action do |global_options,options,args|
|
144
213
|
|
@@ -151,7 +220,7 @@ command :tags do |c|
|
|
151
220
|
if tags.empty? || tags.nil?
|
152
221
|
console_log "No tags in post", {:err => true}
|
153
222
|
else
|
154
|
-
output_tags(tags,options[:format])
|
223
|
+
output_tags(tags,{ :format => options[:format] })
|
155
224
|
end
|
156
225
|
end
|
157
226
|
args.each{|file|
|
@@ -164,7 +233,7 @@ command :tags do |c|
|
|
164
233
|
if tags.empty? || tags.nil?
|
165
234
|
console_log "No tags in post", {:err => true}
|
166
235
|
else
|
167
|
-
output_tags(tags,options[:format])
|
236
|
+
output_tags(tags,{ :format => options[:format] })
|
168
237
|
end
|
169
238
|
else
|
170
239
|
raise "File not found: #{file}"
|
@@ -177,10 +246,10 @@ end
|
|
177
246
|
desc 'Sort the existing tags for posts'
|
178
247
|
arg_name 'filenames', :multiple
|
179
248
|
command :sort do |c|
|
180
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
249
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
181
250
|
c.arg_name 'output_format'
|
182
251
|
c.default_value 'yaml'
|
183
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
252
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
184
253
|
|
185
254
|
c.action do |global_options,options,args|
|
186
255
|
args.each{|file|
|
@@ -197,7 +266,7 @@ command :sort do |c|
|
|
197
266
|
if tags.empty? || tags.nil?
|
198
267
|
console_log "No tags in post", {:err => true}
|
199
268
|
else
|
200
|
-
output_tags(tags,options[:format])
|
269
|
+
output_tags(tags,{ :format => options[:format] })
|
201
270
|
end
|
202
271
|
}
|
203
272
|
end
|
@@ -207,10 +276,10 @@ desc 'Merge multiple tags into one'
|
|
207
276
|
long_desc 'Scans the specified posts for any of the tags, merging any found into the last one in the list'
|
208
277
|
arg_name 'tags to merge merge_tag'
|
209
278
|
command :merge do |c|
|
210
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
279
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
211
280
|
c.arg_name 'output_format'
|
212
281
|
c.default_value 'yaml'
|
213
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
282
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
214
283
|
|
215
284
|
c.action do |global_options, options, args|
|
216
285
|
files = []
|
@@ -239,7 +308,7 @@ command :merge do |c|
|
|
239
308
|
end
|
240
309
|
console_log
|
241
310
|
console_log File.basename(file) + ":"
|
242
|
-
output_tags(new_tags,options[:format])
|
311
|
+
output_tags(new_tags,{ :format => options[:format] })
|
243
312
|
}
|
244
313
|
end
|
245
314
|
end
|
@@ -265,10 +334,10 @@ end
|
|
265
334
|
desc 'Add tags to post(s)'
|
266
335
|
arg_name 'tags', :multiple
|
267
336
|
command :add do |c|
|
268
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
337
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
269
338
|
c.arg_name 'output_format'
|
270
339
|
c.default_value 'yaml'
|
271
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
340
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
272
341
|
|
273
342
|
|
274
343
|
c.action do |global_options,options,args|
|
@@ -298,7 +367,7 @@ command :add do |c|
|
|
298
367
|
|
299
368
|
console_log
|
300
369
|
console_log File.basename(file) + ":"
|
301
|
-
output_tags(tags,options[:format])
|
370
|
+
output_tags(tags,{ :format => options[:format] })
|
302
371
|
}
|
303
372
|
end
|
304
373
|
end
|
@@ -306,10 +375,10 @@ end
|
|
306
375
|
desc 'Remove tags from post(s)'
|
307
376
|
arg_name 'tags', :multiple
|
308
377
|
command :remove do |c|
|
309
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
378
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
310
379
|
c.arg_name 'output_format'
|
311
380
|
c.default_value 'yaml'
|
312
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
381
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
313
382
|
|
314
383
|
c.action do |global_options,options,args|
|
315
384
|
files = []
|
@@ -338,7 +407,7 @@ command :remove do |c|
|
|
338
407
|
|
339
408
|
console_log
|
340
409
|
console_log File.basename(file) + ":"
|
341
|
-
output_tags(tags,options[:format])
|
410
|
+
output_tags(tags,{ :format => options[:format] })
|
342
411
|
}
|
343
412
|
end
|
344
413
|
end
|
@@ -346,10 +415,10 @@ end
|
|
346
415
|
desc 'Generate a list of recommended tags, optionally updating the file'
|
347
416
|
arg_name 'filename', :multiple
|
348
417
|
command :tag do |c|
|
349
|
-
c.desc 'Format to use when outputting tags to console: list, json, csv or yaml. Defaults to yaml.'
|
418
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
350
419
|
c.arg_name 'output_format'
|
351
420
|
c.default_value 'yaml'
|
352
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json)$/, :type => String
|
421
|
+
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
353
422
|
|
354
423
|
c.action do |global_options,options,args|
|
355
424
|
if @piped_content
|
@@ -359,7 +428,7 @@ command :tag do |c|
|
|
359
428
|
console_log
|
360
429
|
console_log "STDIN:", {:err => true}
|
361
430
|
end
|
362
|
-
output_tags(suggestions,options[:format])
|
431
|
+
output_tags(suggestions,{ :format => options[:format] })
|
363
432
|
end
|
364
433
|
end
|
365
434
|
args.each {|file|
|
@@ -381,7 +450,7 @@ command :tag do |c|
|
|
381
450
|
console_log
|
382
451
|
console_log File.basename(file) + ":", {:err => true}
|
383
452
|
end
|
384
|
-
output_tags(suggestions,options[:format])
|
453
|
+
output_tags(suggestions,{ :format => options[:format] })
|
385
454
|
end
|
386
455
|
suggestions = nil
|
387
456
|
else
|
@@ -391,19 +460,36 @@ command :tag do |c|
|
|
391
460
|
end
|
392
461
|
end
|
393
462
|
|
394
|
-
def output_tags(tags,
|
463
|
+
def output_tags(tags,options)
|
464
|
+
format = options[:format] || 'yaml'
|
465
|
+
print0 = options[:print0] || false
|
466
|
+
|
395
467
|
case format
|
396
468
|
when 'list'
|
397
|
-
|
469
|
+
unless print0
|
470
|
+
console_log tags.join("\n")
|
471
|
+
else
|
472
|
+
console_log tags.map {|tag|
|
473
|
+
if tag.strip =~ /\b\s\b/
|
474
|
+
%Q{"#{tag.strip}"}
|
475
|
+
else
|
476
|
+
tag.strip
|
477
|
+
end
|
478
|
+
}.join(" ")
|
479
|
+
end
|
398
480
|
when 'csv'
|
399
481
|
console_log tags.to_csv
|
400
482
|
when 'json'
|
401
483
|
out = {}
|
402
484
|
out['tags'] = tags
|
403
485
|
console_log out.to_json
|
486
|
+
when 'plist'
|
487
|
+
out = {}
|
488
|
+
console_log tags.to_plist
|
404
489
|
else
|
405
490
|
out = {}
|
406
|
-
|
491
|
+
options[:grouping] ||= "tags"
|
492
|
+
out[options[:grouping]] = tags
|
407
493
|
console_log out.to_yaml
|
408
494
|
end
|
409
495
|
end
|
data/lib/jtag.rb
CHANGED
data/lib/jtag/version.rb
CHANGED
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: jtag
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.10
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2013-
|
12
|
+
date: 2013-09-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -91,6 +91,22 @@ dependencies:
|
|
91
91
|
- - ! '>='
|
92
92
|
- !ruby/object:Gem::Version
|
93
93
|
version: '0'
|
94
|
+
- !ruby/object:Gem::Dependency
|
95
|
+
name: plist
|
96
|
+
requirement: !ruby/object:Gem::Requirement
|
97
|
+
none: false
|
98
|
+
requirements:
|
99
|
+
- - ! '>='
|
100
|
+
- !ruby/object:Gem::Version
|
101
|
+
version: '0'
|
102
|
+
type: :runtime
|
103
|
+
prerelease: false
|
104
|
+
version_requirements: !ruby/object:Gem::Requirement
|
105
|
+
none: false
|
106
|
+
requirements:
|
107
|
+
- - ! '>='
|
108
|
+
- !ruby/object:Gem::Version
|
109
|
+
version: '0'
|
94
110
|
description:
|
95
111
|
email: me@brettterpstra.com
|
96
112
|
executables:
|
@@ -130,18 +146,12 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
130
146
|
- - ! '>='
|
131
147
|
- !ruby/object:Gem::Version
|
132
148
|
version: '0'
|
133
|
-
segments:
|
134
|
-
- 0
|
135
|
-
hash: 2297591427914032875
|
136
149
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
137
150
|
none: false
|
138
151
|
requirements:
|
139
152
|
- - ! '>='
|
140
153
|
- !ruby/object:Gem::Version
|
141
154
|
version: '0'
|
142
|
-
segments:
|
143
|
-
- 0
|
144
|
-
hash: 2297591427914032875
|
145
155
|
requirements: []
|
146
156
|
rubyforge_project:
|
147
157
|
rubygems_version: 1.8.25
|