jtag 0.1.16 → 0.1.18
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/bin/jtag +55 -57
- data/lib/jtag/jekylltag.rb +17 -11
- data/lib/jtag/version.rb +1 -1
- metadata +3 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 072e652c6a5dfe8fa5140e7f2f7af1072826e3af41c6d89c030880cedf54041b
|
4
|
+
data.tar.gz: 99a3969d116038f099991f500d242b9c3fef1934c4ce24bcfbf8a5b27fb8a83e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 3bbca2f392910ab5d86b25a280cf1be8e350b03b34e2fa281f128edeb22a760bb67e604036289a278e2a85d7053ea4d510674e5df8ee8271b9e1ec8820e84575
|
7
|
+
data.tar.gz: fe8dca46e901ebba1cb289c76b4293725cbf91252ee17a95e3f9e9c7dd11697b416691a8b77a300c1caf7499c055b3f7d6466a70aebb436c709f3c64c282add7
|
data/bin/jtag
CHANGED
@@ -11,10 +11,11 @@ version Jtag::VERSION
|
|
11
11
|
|
12
12
|
@config_files = %w{blacklist.txt config.yml stopwords.txt synonyms.yml}
|
13
13
|
@config_target = File.expand_path("~/.jtag")
|
14
|
+
@piped_content = nil
|
14
15
|
|
15
16
|
def config_files_complete?
|
16
17
|
@config_files.each do |file|
|
17
|
-
return false unless File.
|
18
|
+
return false unless File.exist?(File.join(@config_target, file))
|
18
19
|
end
|
19
20
|
true
|
20
21
|
end
|
@@ -22,18 +23,18 @@ end
|
|
22
23
|
desc 'Debug level'
|
23
24
|
default_value '0'
|
24
25
|
arg_name 'debug_level'
|
25
|
-
flag [
|
26
|
+
flag %i[d debug], :must_match => /\d+/, :type => Integer, :default_value => 0
|
26
27
|
|
27
28
|
desc 'Run silently'
|
28
|
-
switch [
|
29
|
+
switch %i[s silent]
|
29
30
|
|
30
31
|
desc 'Perform case-insensitive matches and searches'
|
31
|
-
switch [
|
32
|
+
switch %i[i case_insensitive]
|
32
33
|
|
33
34
|
desc "Test (dry run, don't update files)"
|
34
35
|
long_desc "Run all commands and show results on the command line, but don't overwrite/update any files"
|
35
36
|
default_value false
|
36
|
-
switch [
|
37
|
+
switch %i[t test]
|
37
38
|
|
38
39
|
def console_log(msg="", options={})
|
39
40
|
err = options[:err] || false
|
@@ -52,7 +53,7 @@ def console_log(msg="", options={})
|
|
52
53
|
unless err
|
53
54
|
$stdout.puts msg
|
54
55
|
else
|
55
|
-
|
56
|
+
warn msg
|
56
57
|
end
|
57
58
|
end
|
58
59
|
|
@@ -91,7 +92,7 @@ def write_config(atomic=false)
|
|
91
92
|
end
|
92
93
|
|
93
94
|
@config_files.each do |file|
|
94
|
-
unless File.
|
95
|
+
unless File.exist?(File.join(@config_target,file))
|
95
96
|
source_file = File.join(config_source,file)
|
96
97
|
target_file = File.join(@config_target,file)
|
97
98
|
FileUtils.cp(source_file, target_file)
|
@@ -110,12 +111,12 @@ command :search do |c|
|
|
110
111
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
111
112
|
c.arg_name 'output_format'
|
112
113
|
c.default_value 'yaml'
|
113
|
-
c.flag [
|
114
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/i, :type => String
|
114
115
|
|
115
116
|
c.desc 'Include tag counts'
|
116
117
|
c.arg_name 'counts'
|
117
118
|
c.default_value false
|
118
|
-
c.switch [
|
119
|
+
c.switch %i[c counts]
|
119
120
|
|
120
121
|
c.action do |global_options,options,args|
|
121
122
|
tags = @jt.get_tags({:counts => true})
|
@@ -152,12 +153,12 @@ command :posts_tagged do |c|
|
|
152
153
|
c.desc 'Boolean operator for multiple tags (AND/OR/NOT)'
|
153
154
|
c.arg_name 'bool'
|
154
155
|
c.default_value 'OR'
|
155
|
-
c.flag [
|
156
|
+
c.flag %i[b bool], :must_match => /(AND|OR|NOT)/i, :type => String
|
156
157
|
|
157
158
|
c.desc 'Format to use when outputting file list: list, json, plist, csv or yaml. Defaults to list.'
|
158
159
|
c.arg_name 'output_format'
|
159
160
|
c.default_value 'list'
|
160
|
-
c.flag [
|
161
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
161
162
|
|
162
163
|
c.desc 'If output format is list, print without newlines.'
|
163
164
|
c.switch [:print0]
|
@@ -169,20 +170,20 @@ command :posts_tagged do |c|
|
|
169
170
|
matches = []
|
170
171
|
args.length.times do
|
171
172
|
arg = args.pop
|
172
|
-
if File.
|
173
|
+
if File.exist?(arg)
|
173
174
|
files.push(arg)
|
174
175
|
else
|
175
176
|
tags.push(arg)
|
176
177
|
end
|
177
178
|
end
|
178
179
|
if files.empty?
|
179
|
-
if @jt.default_post_location && File.
|
180
|
+
if @jt.default_post_location && File.exist?(File.dirname(@jt.default_post_location))
|
180
181
|
files = Dir.glob(@jt.default_post_location)
|
181
182
|
end
|
182
183
|
end
|
183
184
|
exit_now! "No valid filename in arguments" if files.empty?
|
184
185
|
files.each {|file|
|
185
|
-
if File.
|
186
|
+
if File.exist?(file)
|
186
187
|
post_tags = @jt.post_tags(file)
|
187
188
|
|
188
189
|
if bool == "AND"
|
@@ -225,22 +226,22 @@ command :loners do |c|
|
|
225
226
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
226
227
|
c.arg_name 'output_format'
|
227
228
|
c.default_value 'yaml'
|
228
|
-
c.flag [
|
229
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
229
230
|
|
230
231
|
c.desc 'Upper limit for how many posts a tag can be attached to and still be a loner'
|
231
232
|
c.arg_name 'max'
|
232
233
|
c.default_value '2'
|
233
|
-
c.flag [
|
234
|
+
c.flag %i[m max], :default_value => 2, :must_match => /^\d+$/
|
234
235
|
|
235
236
|
c.desc "Remove tags with fewer than X posts attached"
|
236
|
-
c.switch [
|
237
|
+
c.switch %i[r remove], :default_value => false
|
237
238
|
|
238
239
|
c.desc "Display output without attached occurence counts"
|
239
240
|
c.switch [:no_counts], :default_value => false
|
240
241
|
|
241
242
|
c.desc 'Output a file list of tags that can be edited and passed back in for removing'
|
242
243
|
c.arg_name 'filename'
|
243
|
-
c.flag [
|
244
|
+
c.flag %i[e edit], :default_value => false, :type => String
|
244
245
|
|
245
246
|
c.action do |global_options,options,args|
|
246
247
|
max = options[:m].to_i
|
@@ -254,7 +255,7 @@ command :loners do |c|
|
|
254
255
|
|
255
256
|
if options[:e]
|
256
257
|
path = File.expand_path(options[:e])
|
257
|
-
while File.
|
258
|
+
while File.exist?(path)
|
258
259
|
if path =~ /(\d+)(\.[^\.]+?)?$/
|
259
260
|
path.sub!(/(\d+)(\.[^\.]+?)?$/) do |m|
|
260
261
|
$1.next! + $2
|
@@ -290,10 +291,10 @@ command :loners do |c|
|
|
290
291
|
files = []
|
291
292
|
args.length.times do
|
292
293
|
arg = args.pop
|
293
|
-
files.push(arg) if File.
|
294
|
+
files.push(arg) if File.exist?(arg)
|
294
295
|
end
|
295
296
|
if files.empty?
|
296
|
-
if @jt.default_post_location && File.
|
297
|
+
if @jt.default_post_location && File.exist?(File.dirname(@jt.default_post_location))
|
297
298
|
files = Dir.glob(@jt.default_post_location)
|
298
299
|
end
|
299
300
|
end
|
@@ -310,7 +311,7 @@ command :loners do |c|
|
|
310
311
|
}
|
311
312
|
}
|
312
313
|
unless global_options[:t]
|
313
|
-
@jt.update_file_tags(file,tags)
|
314
|
+
@jt.update_file_tags(file, tags)
|
314
315
|
console_log "Updated tags for #{file}", :log => true
|
315
316
|
end
|
316
317
|
|
@@ -333,15 +334,15 @@ command :tags do |c|
|
|
333
334
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
334
335
|
c.arg_name 'output_format'
|
335
336
|
c.default_value 'yaml'
|
336
|
-
c.flag [
|
337
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
337
338
|
|
338
339
|
c.action do |global_options,options,args|
|
339
340
|
|
340
341
|
if @piped_content
|
341
|
-
tags = @jt.post_tags(@piped_content,true)
|
342
|
+
tags = @jt.post_tags(@piped_content, true)
|
342
343
|
if args.length > 1
|
343
344
|
console_log
|
344
|
-
console_log
|
345
|
+
console_log 'STDIN:'
|
345
346
|
end
|
346
347
|
if tags.empty? || tags.nil?
|
347
348
|
console_log "No tags in post", {:err => true}
|
@@ -350,7 +351,7 @@ command :tags do |c|
|
|
350
351
|
end
|
351
352
|
end
|
352
353
|
args.each{|file|
|
353
|
-
if File.
|
354
|
+
if File.exist?(file)
|
354
355
|
tags = @jt.post_tags(file)
|
355
356
|
if args.length > 1
|
356
357
|
console_log
|
@@ -375,7 +376,7 @@ command :sort do |c|
|
|
375
376
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
376
377
|
c.arg_name 'output_format'
|
377
378
|
c.default_value 'yaml'
|
378
|
-
c.flag [
|
379
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
379
380
|
|
380
381
|
c.action do |global_options,options,args|
|
381
382
|
args.each{|file|
|
@@ -404,21 +405,21 @@ command :merge do |c|
|
|
404
405
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
405
406
|
c.arg_name 'output_format'
|
406
407
|
c.default_value 'yaml'
|
407
|
-
c.flag [
|
408
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
408
409
|
|
409
410
|
c.action do |global_options, options, args|
|
410
411
|
files = []
|
411
412
|
tags = []
|
412
413
|
args.length.times do
|
413
414
|
arg = args.pop
|
414
|
-
if File.
|
415
|
+
if File.exist?(arg)
|
415
416
|
files.push(arg)
|
416
417
|
else
|
417
418
|
tags.push(arg)
|
418
419
|
end
|
419
420
|
end
|
420
421
|
if files.empty?
|
421
|
-
if @jt.default_post_location && File.
|
422
|
+
if @jt.default_post_location && File.exist?(File.dirname(@jt.default_post_location))
|
422
423
|
files = Dir.glob(@jt.default_post_location)
|
423
424
|
end
|
424
425
|
end
|
@@ -469,7 +470,7 @@ command :add do |c|
|
|
469
470
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
470
471
|
c.arg_name 'output_format'
|
471
472
|
c.default_value 'yaml'
|
472
|
-
c.flag [
|
473
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
473
474
|
|
474
475
|
|
475
476
|
c.action do |global_options,options,args|
|
@@ -477,14 +478,14 @@ command :add do |c|
|
|
477
478
|
new_tags = []
|
478
479
|
args.length.times do
|
479
480
|
arg = args.pop
|
480
|
-
if File.
|
481
|
+
if File.exist?(arg)
|
481
482
|
files.push(arg)
|
482
483
|
else
|
483
484
|
new_tags.push(arg)
|
484
485
|
end
|
485
486
|
end
|
486
487
|
if files.empty?
|
487
|
-
if @jt.default_post_location && File.
|
488
|
+
if @jt.default_post_location && File.exist?(File.dirname(@jt.default_post_location))
|
488
489
|
files = Dir.glob(@jt.default_post_location)
|
489
490
|
end
|
490
491
|
end
|
@@ -497,7 +498,7 @@ command :add do |c|
|
|
497
498
|
tags.uniq!
|
498
499
|
tags.sort!
|
499
500
|
unless global_options[:t]
|
500
|
-
@jt.update_file_tags(file,tags)
|
501
|
+
@jt.update_file_tags(file, tags)
|
501
502
|
console_log "Updated tags for #{file}", :log => true
|
502
503
|
end
|
503
504
|
|
@@ -514,26 +515,26 @@ command :remove do |c|
|
|
514
515
|
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Defaults to yaml.'
|
515
516
|
c.arg_name 'output_format'
|
516
517
|
c.default_value 'yaml'
|
517
|
-
c.flag [
|
518
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
518
519
|
|
519
520
|
c.desc 'A filepath to a list of tags to be removed'
|
520
521
|
c.long_desc 'One tag per line, and leading numbers and pipes (|) will be ignored. This file format is generated automatically by the `loners` command, but any text file will do the trick.'
|
521
522
|
c.arg_name 'input_file'
|
522
|
-
c.flag [
|
523
|
+
c.flag %i[p path], :type => String
|
523
524
|
|
524
525
|
c.action do |global_options,options,args|
|
525
526
|
files = []
|
526
527
|
remove_tags = []
|
527
528
|
args.length.times do
|
528
529
|
arg = args.pop
|
529
|
-
if File.
|
530
|
+
if File.exist?(arg)
|
530
531
|
files.push(arg)
|
531
532
|
else
|
532
533
|
remove_tags.push(arg) unless options[:p]
|
533
534
|
end
|
534
535
|
end
|
535
536
|
if files.empty?
|
536
|
-
if @jt.default_post_location && File.
|
537
|
+
if @jt.default_post_location && File.exist?(File.dirname(@jt.default_post_location))
|
537
538
|
files = Dir.glob(@jt.default_post_location)
|
538
539
|
end
|
539
540
|
end
|
@@ -541,7 +542,7 @@ command :remove do |c|
|
|
541
542
|
|
542
543
|
if options[:p]
|
543
544
|
path = File.expand_path(options[:p])
|
544
|
-
exit_now! "Input file does not appear to be where you think it is." unless File.
|
545
|
+
exit_now! "Input file does not appear to be where you think it is." unless File.exist?(path)
|
545
546
|
IO.read(path).each_line {|l|
|
546
547
|
next if l =~ /^\s*#/
|
547
548
|
if l =~ /^(?:[\s\d])*(?:\|\s*)?(\S.*?)$/
|
@@ -565,7 +566,7 @@ command :remove do |c|
|
|
565
566
|
}
|
566
567
|
}
|
567
568
|
unless global_options[:t]
|
568
|
-
@jt.update_file_tags(file,tags)
|
569
|
+
@jt.update_file_tags(file, tags)
|
569
570
|
console_log "Updated tags for #{file}", :log => true
|
570
571
|
end
|
571
572
|
|
@@ -579,24 +580,25 @@ end
|
|
579
580
|
desc 'Generate a list of recommended tags, optionally updating the file'
|
580
581
|
arg_name 'file_pattern', :multiple
|
581
582
|
command :tag do |c|
|
582
|
-
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml.
|
583
|
+
c.desc 'Format to use when outputting tags to console: list, json, plist, csv or yaml. Use "complete" to output full text when input is STDIN.'
|
583
584
|
c.arg_name 'output_format'
|
584
|
-
c.default_value 'yaml'
|
585
|
-
c.flag [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
|
585
|
+
c.flag %i[f format], :must_match => /^(csv|list|yaml|json|plist|complete)$/, :type => String, :default_value => 'yaml'
|
586
586
|
|
587
|
-
c.action do |global_options,options,args|
|
587
|
+
c.action do |global_options, options, args|
|
588
588
|
if @piped_content
|
589
589
|
suggestions = @jt.suggest(@piped_content)
|
590
|
-
if
|
591
|
-
|
592
|
-
|
593
|
-
|
594
|
-
|
595
|
-
|
590
|
+
if args.length > 0
|
591
|
+
console_log
|
592
|
+
console_log 'STDIN:', :err => true
|
593
|
+
end
|
594
|
+
if options[:format] == 'complete'
|
595
|
+
@jt.update_file_tags(@piped_content, suggestions, true)
|
596
|
+
else
|
597
|
+
output_tags(suggestions, :format => options[:format], :filename => nil)
|
596
598
|
end
|
597
599
|
end
|
598
600
|
args.each {|file|
|
599
|
-
if File.
|
601
|
+
if File.exist?(File.expand_path(file))
|
600
602
|
input = IO.read(File.expand_path(file))
|
601
603
|
suggestions = @jt.suggest(input)
|
602
604
|
|
@@ -670,7 +672,7 @@ end
|
|
670
672
|
# end
|
671
673
|
# end
|
672
674
|
|
673
|
-
pre do |global,command,options,args|
|
675
|
+
pre do |global, command, options, args|
|
674
676
|
# Use skips_pre before a command to skip this block
|
675
677
|
# on that command only
|
676
678
|
@silent = global[:silent]
|
@@ -690,11 +692,7 @@ pre do |global,command,options,args|
|
|
690
692
|
global[:config] = YAML::load(File.open(configfile,"r"))
|
691
693
|
global[:support] = File.expand_path("~/.jtag")
|
692
694
|
|
693
|
-
|
694
|
-
@piped_content = STDIN.read
|
695
|
-
else
|
696
|
-
@piped_content = false
|
697
|
-
end
|
695
|
+
@piped_content = STDIN.stat.size > 0 ? STDIN.read : nil
|
698
696
|
|
699
697
|
@jt = JTag.new(global[:support], global[:config])
|
700
698
|
|
data/lib/jtag/jekylltag.rb
CHANGED
@@ -64,7 +64,7 @@ class JTag
|
|
64
64
|
end
|
65
65
|
|
66
66
|
def synonyms
|
67
|
-
if File.
|
67
|
+
if File.exist?(File.join(@support,"synonyms.yml"))
|
68
68
|
syn = YAML::load(File.open(File.join(@support,"synonyms.yml")))
|
69
69
|
compiled = {}
|
70
70
|
syn.each {|k,v|
|
@@ -78,8 +78,8 @@ class JTag
|
|
78
78
|
compiled
|
79
79
|
end
|
80
80
|
|
81
|
-
def split_post(file)
|
82
|
-
input = IO.read(file)
|
81
|
+
def split_post(file, piped = false)
|
82
|
+
input = piped ? file : IO.read(file)
|
83
83
|
# Check to see if it's a full post with YAML headers
|
84
84
|
post_parts = input.split(/^[\.\-]{3}\s*$/)
|
85
85
|
if post_parts.length >= 3
|
@@ -94,7 +94,7 @@ class JTag
|
|
94
94
|
|
95
95
|
def post_tags(file, piped=false)
|
96
96
|
begin
|
97
|
-
input = piped ? file : IO.read(file)
|
97
|
+
input = piped ? file.strip : IO.read(file)
|
98
98
|
yaml = YAML::load(input)
|
99
99
|
return yaml[@tags_key] || []
|
100
100
|
rescue
|
@@ -191,15 +191,21 @@ class JTag
|
|
191
191
|
end
|
192
192
|
end
|
193
193
|
|
194
|
-
def update_file_tags(file, tags)
|
194
|
+
def update_file_tags(file, tags, piped = false)
|
195
195
|
begin
|
196
|
-
if File.
|
197
|
-
yaml, after = split_post(file)
|
196
|
+
if File.exist?(file) || piped
|
197
|
+
yaml, after = split_post(file, piped)
|
198
198
|
yaml[@tags_key] = tags
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
|
199
|
+
if piped
|
200
|
+
puts yaml.to_yaml
|
201
|
+
puts "---"
|
202
|
+
puts after
|
203
|
+
else
|
204
|
+
File.open(file,'w+') do |f|
|
205
|
+
f.puts yaml.to_yaml
|
206
|
+
f.puts "---"
|
207
|
+
f.puts after
|
208
|
+
end
|
203
209
|
end
|
204
210
|
else
|
205
211
|
raise "File does not exist: #{file}"
|
data/lib/jtag/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
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.18
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Brett Terpstra
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: rake
|
@@ -124,7 +124,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
124
124
|
- !ruby/object:Gem::Version
|
125
125
|
version: '0'
|
126
126
|
requirements: []
|
127
|
-
rubygems_version: 3.
|
127
|
+
rubygems_version: 3.4.0.dev
|
128
128
|
signing_key:
|
129
129
|
specification_version: 4
|
130
130
|
summary: Auto-tagging and tagging tools for Jekyll
|