jtag 0.1.16 → 0.1.17

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: df37574933df4c54b9593793bb1f737b4446c8db712a8ea01ac7019b3ff22c05
4
- data.tar.gz: 359c87ed6440b1423d69a251ff5f37e47806c6c9040e091b047cd2da48da41c2
3
+ metadata.gz: f68f1e95a41e56ce886f6b77f116f7617918d99374b0a8bc093d06f55ec63fa1
4
+ data.tar.gz: b1e2d8fe246baba7cc17b2fe86e867e91f0beed1c631021b6b02512ef8ed2641
5
5
  SHA512:
6
- metadata.gz: 640c52f5097dd1df6b5e9deff22cf26ed23c36f15ecfb98f489a77039036256209a7975c3cc0d5296bececf665b8be6f0e1f7d6f74756bcd60d2d22970e59591
7
- data.tar.gz: a96984e24677d8656b91b9dfdcc9d3f21ef49e4c76bb59fb1a55275329d724319aa6a314b7d836e5bc712ce1d4ac639c86538c64ee9baedb01d16666045e1fca
6
+ metadata.gz: 767f4d931006ff59a30fb32d0f156703026f34b5c12c86fbdc02ebb56b0f3580618a411cfda9666fb299793dd88d34dec6b4dcf0804932f4f46df6dfd86b864f
7
+ data.tar.gz: f9c405479a2bb93999598387815fe37d626e84391fce3f650c308bc1b4c4f1ac48a6dbb6a1e7927dedb03cd41c32c847c2a0c612d423b9105e912c085976cc0b
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.exists?(File.join(@config_target,file))
18
+ return false unless File.exists?(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 [:d,:debug], :must_match => /\d+/, :type => Integer, :default_value => 0
26
+ flag %i[d debug], :must_match => /\d+/, :type => Integer, :default_value => 0
26
27
 
27
28
  desc 'Run silently'
28
- switch [:s,:silent]
29
+ switch %i[s silent]
29
30
 
30
31
  desc 'Perform case-insensitive matches and searches'
31
- switch [:i,:case_insensitive]
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 [:t,:test]
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
- $stderr.puts msg
56
+ warn msg
56
57
  end
57
58
  end
58
59
 
@@ -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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/i, :type => String
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 [:c,:counts]
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 [:b,:bool], :must_match => /(AND|OR|NOT)/i, :type => String
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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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]
@@ -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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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 [:m,:max], :default_value => 2, :must_match => /^\d+$/
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 [:r,:remove], :default_value => false
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 [:e,:edit], :default_value => false, :type => String
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
@@ -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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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 "STDIN:"
345
+ console_log 'STDIN:'
345
346
  end
346
347
  if tags.empty? || tags.nil?
347
348
  console_log "No tags in post", {:err => true}
@@ -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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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,7 +405,7 @@ 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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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 = []
@@ -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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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|
@@ -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,12 +515,12 @@ 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 [:f,:format], :must_match => /^(csv|list|yaml|json|plist)$/, :type => String
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 [:p,:path], :type => String
523
+ c.flag %i[p path], :type => String
523
524
 
524
525
  c.action do |global_options,options,args|
525
526
  files = []
@@ -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,20 +580,21 @@ 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. Defaults to 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 !global_options[:s] || global_options[:t]
591
- if args.length > 1
592
- console_log
593
- console_log "STDIN:", :err => true
594
- end
595
- output_tags(suggestions, :format => options[:format], :filename => file )
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|
@@ -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
- if STDIN.stat.size > 0
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
 
@@ -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.exists?(file)
197
- yaml, after = split_post(file)
196
+ if File.exists?(file) || piped
197
+ yaml, after = split_post(file, piped)
198
198
  yaml[@tags_key] = tags
199
- File.open(file,'w+') do |f|
200
- f.puts yaml.to_yaml
201
- f.puts "---"
202
- f.puts after
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
@@ -1,3 +1,3 @@
1
1
  module Jtag
2
- VERSION = '0.1.16'
2
+ VERSION = '0.1.17'
3
3
  end
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.16
4
+ version: 0.1.17
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2021-05-14 00:00:00.000000000 Z
11
+ date: 2021-08-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rake