howzit 2.0.9 → 2.0.10

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e11e4e9f19c26666de0d9dbfbfd0ab1b3c1bee495575fe0962ab5157a185e613
4
- data.tar.gz: 7430c1da6d45f7dc873e01a8c1e6618da2dab503659921b9b72d690ad7aff181
3
+ metadata.gz: bd8307dc1bdbf51c7a78333c5880990b0bf82acb3fb2401d9e9969fe312ce125
4
+ data.tar.gz: 72ef1a744da1debcd5faf9ff9ee170eae3389b04e585cd652450eb65ba177c30
5
5
  SHA512:
6
- metadata.gz: 739879dd1a53689e005511745003dd9b9d2ff5a8fa964cec3cb1754ef78e740c488d0a9040cee6b6de5e5eaf62a4a9c50dcc74a236db732e1c78ef4f9c8978cd
7
- data.tar.gz: '009601634be888e709ee5709fc2bb990b5dff1a274144469621a9b23dc5108778fec2f8838fc46f03999df8c31d9872f3ad8b9de57afb6bb534035a8f8070c25'
6
+ metadata.gz: affa665e5f83a8b836f5fe0a3d3c8e178d6fc880bcf3cecfe13afe44e61f4392831a45ff57f1a412a6ae7878f5cd7c00cd541aea1d780eb2b61aa01247268855
7
+ data.tar.gz: 85449c9184c5927d56acbd00e4086f11a9f4ee85085bfe07c12eb3e7b27e71c00eccee203fd73bda94919dfef000ead8f99f61e275b4d73700b442e25caa38c9
data/CHANGELOG.md CHANGED
@@ -1,3 +1,12 @@
1
+ ### 2.0.10
2
+
3
+ 2022-08-05 08:17
4
+
5
+ #### IMPROVED
6
+
7
+ - Provide more helpful feedback if no content is found in build note
8
+ - Confirm whether the user wants to create a new note when one isn't found
9
+
1
10
  ### 2.0.9
2
11
 
3
12
  2022-08-05 07:29
@@ -7,10 +7,27 @@ module Howzit
7
7
 
8
8
  attr_reader :metadata, :title
9
9
 
10
+ ##
11
+ ## Initialize a build note
12
+ ##
13
+ ## @param file [String] The path to the build note file
14
+ ## @param args [Array] additional args
15
+ ##
10
16
  def initialize(file: nil, args: [])
11
17
  @topics = []
12
- create_note if note_file.nil?
13
- @metadata = Util.read_file(note_file).split(/^#/)[0].strip.get_metadata
18
+ if note_file.nil?
19
+ res = Prompt.yn('No build notes file found, create one?', default: true)
20
+
21
+ create_note if res
22
+ Process.exit 0
23
+ end
24
+ content = Util.read_file(note_file)
25
+ if content.nil? || content.empty?
26
+ Howzit.console.error("{br}No content found in build note (#{note_file}){x}".c)
27
+ Process.exit 1
28
+ else
29
+ @metadata = content.split(/^#/)[0].strip.get_metadata
30
+ end
14
31
 
15
32
  read_help(file)
16
33
  end
@@ -19,14 +36,25 @@ module Howzit
19
36
  puts "#<Howzit::BuildNote @topics=[#{@topics.count}]>"
20
37
  end
21
38
 
39
+ ##
40
+ ## Public method to begin processing the build note based on command line options
41
+ ##
22
42
  def run
23
43
  process
24
44
  end
25
45
 
46
+ ##
47
+ ## Public method to open build note in editor
48
+ ##
26
49
  def edit
27
50
  edit_note
28
51
  end
29
52
 
53
+ ##
54
+ ## Find a topic based on a fuzzy match
55
+ ##
56
+ ## @param term [String] The search term
57
+ ##
30
58
  def find_topic(term)
31
59
  @topics.filter do |topic|
32
60
  rx = term.to_rx
@@ -34,11 +62,19 @@ module Howzit
34
62
  end
35
63
  end
36
64
 
65
+ ##
66
+ ## Call grep on all topics, filtering out those that don't match
67
+ ##
68
+ ## @param term [String] The search pattern
69
+ ##
37
70
  def grep(term)
38
71
  @topics.filter { |topic| topic.grep(term) }
39
72
  end
40
73
 
41
74
  # Output a list of topic titles
75
+ #
76
+ # @return [String] formatted list of topics in build note
77
+ #
42
78
  def list
43
79
  output = []
44
80
  output.push("{bg}Topics:{x}\n".c)
@@ -48,14 +84,32 @@ module Howzit
48
84
  output.join("\n")
49
85
  end
50
86
 
87
+
88
+ ##
89
+ ## Return an array of topic titles
90
+ ##
91
+ ## @return [Array] array of topic titles
92
+ ##
51
93
  def list_topics
52
94
  @topics.map { |topic| topic.title }
53
95
  end
54
96
 
97
+ ##
98
+ ## Return a list of topic titles suitable for shell completion
99
+ ##
100
+ ## @return [String] newline-separated list of topic titles
101
+ ##
55
102
  def list_completions
56
103
  list_topics.join("\n")
57
104
  end
58
105
 
106
+ ##
107
+ ## Return a list of topics containing @directives,
108
+ ## suitable for shell completion
109
+ ##
110
+ ## @return [String] newline-separated list of topic
111
+ ## titles
112
+ ##
59
113
  def list_runnable_completions
60
114
  output = []
61
115
  @topics.each do |topic|
@@ -64,6 +118,12 @@ module Howzit
64
118
  output.join("\n")
65
119
  end
66
120
 
121
+ ##
122
+ ## Return a formatted list of topics containing
123
+ ## @directives suitable for console output
124
+ ##
125
+ ## @return [String] formatted list
126
+ ##
67
127
  def list_runnable
68
128
  output = []
69
129
  output.push(%({bg}"Runnable" Topics:{x}\n).c)
@@ -82,6 +142,11 @@ module Howzit
82
142
  output.join("\n")
83
143
  end
84
144
 
145
+ ##
146
+ ## Read the help file contents
147
+ ##
148
+ ## @param file [String] The filepath
149
+ ##
85
150
  def read_file(file)
86
151
  read_help_file(file)
87
152
  end
@@ -210,6 +275,13 @@ module Howzit
210
275
  buildnotes.reverse
211
276
  end
212
277
 
278
+ ##
279
+ ## Test if the filename matches the conditions to be a build note
280
+ ##
281
+ ## @param filename [String] The filename to test
282
+ ##
283
+ ## @return [Boolean] true if filename passes test
284
+ ##
213
285
  def build_note?(filename)
214
286
  return false if filename.downcase !~ /^(howzit[^.]*|build[^.]+)/
215
287
 
@@ -218,6 +290,11 @@ module Howzit
218
290
  true
219
291
  end
220
292
 
293
+ ##
294
+ ## Glob current directory for valid build note filenames
295
+ ##
296
+ ## @return [String] file path
297
+ ##
221
298
  def glob_note
222
299
  filename = nil
223
300
  # Check for a build note file in the current folder. Filename must start
@@ -232,6 +309,13 @@ module Howzit
232
309
  filename
233
310
  end
234
311
 
312
+ ##
313
+ ## Search for a valid build note, checking current
314
+ ## directory, git top level directory, and parent
315
+ ## directories
316
+ ##
317
+ ## @return [String] filepath
318
+ ##
235
319
  def find_note_file
236
320
  filename = glob_note
237
321
 
@@ -253,6 +337,11 @@ module Howzit
253
337
  File.expand_path(filename)
254
338
  end
255
339
 
340
+ ##
341
+ ## Search upstream directories for build notes
342
+ ##
343
+ ## @return [Array] array of build note paths
344
+ ##
256
345
  def read_upstream
257
346
  buildnotes = glob_upstream
258
347
 
@@ -263,6 +352,13 @@ module Howzit
263
352
  topics_dict
264
353
  end
265
354
 
355
+ ##
356
+ ## Test to ensure that any `required` metadata in a
357
+ ## template is fulfilled by the build note
358
+ ##
359
+ ## @param template [String] The template to read
360
+ ## from
361
+ ##
266
362
  def ensure_requirements(template)
267
363
  t_leader = Util.read_file(template).split(/^#/)[0].strip
268
364
  if t_leader.length > 0
@@ -271,8 +367,8 @@ module Howzit
271
367
  required = t_meta['required'].strip.split(/\s*,\s*/)
272
368
  required.each do |req|
273
369
  unless @metadata.keys.include?(req.downcase)
274
- Howzit.console.error %({xr}ERROR: Missing required metadata key from template '{bw}#{File.basename(template, '.md')}{xr}'{x}).c
275
- Howzit.console.error %({xr}Please define {by}#{req.downcase}{xr} in build notes{x}).c
370
+ Howzit.console.error %({bRw}ERROR:{xbr} Missing required metadata key from template '{bw}#{File.basename(template, '.md')}{xr}'{x}).c
371
+ Howzit.console.error %({br}Please define {by}#{req.downcase}{xr} in build notes{x}).c
276
372
  Process.exit 1
277
373
  end
278
374
  end
@@ -280,6 +376,11 @@ module Howzit
280
376
  end
281
377
  end
282
378
 
379
+ ##
380
+ ## Read a list of topics from an included template
381
+ ##
382
+ ## @param content [String] The template contents
383
+ ##
283
384
  def get_template_topics(content)
284
385
  leader = content.split(/^#/)[0].strip
285
386
 
@@ -327,10 +428,16 @@ module Howzit
327
428
  template_topics
328
429
  end
329
430
 
330
- def include_file(m)
331
- file = File.expand_path(m[1])
431
+ ##
432
+ ## Import the contents of a filename as new topics
433
+ ##
434
+ ## @param mtch [MatchData] the filename match from
435
+ ## the include directive
436
+ ##
437
+ def include_file(mtch)
438
+ file = File.expand_path(mtch[1])
332
439
 
333
- return m[0] unless File.exist?(file)
440
+ return mtch[0] unless File.exist?(file)
334
441
 
335
442
  content = Util.read_file(file)
336
443
  home = ENV['HOME']
@@ -345,6 +452,11 @@ module Howzit
345
452
  end
346
453
  end
347
454
 
455
+ ##
456
+ ## Get the title of the build note (top level header)
457
+ ##
458
+ ## @param truncate [Integer] Truncate to width
459
+ ##
348
460
  def note_title(truncate = 0)
349
461
  help = Util.read_file(note_file)
350
462
  title = help.match(/(?:^(\S.*?)(?=\n==)|^# ?(.*?)$)/)
@@ -357,7 +469,13 @@ module Howzit
357
469
  title && truncate.positive? ? title.trunc(truncate) : title
358
470
  end
359
471
 
360
- # Read in the build notes file and output a hash of "Title" => contents
472
+ # Read in the build notes file and output a hash of
473
+ # "Title" => contents
474
+ #
475
+ # @param path [String] The build note path
476
+ #
477
+ # @return [Array] array of Topics
478
+ #
361
479
  def read_help_file(path = nil)
362
480
  topics = []
363
481
 
@@ -365,6 +483,11 @@ module Howzit
365
483
 
366
484
  help = Util.read_file(filename)
367
485
 
486
+ if help.nil? || help.empty?
487
+ Howzit.console.error("{br}No content found in #{filename}{x}".c)
488
+ Process.exit 1
489
+ end
490
+
368
491
  @title = note_title
369
492
 
370
493
  help.gsub!(/@include\((.*?)\)/) do
@@ -403,6 +526,11 @@ module Howzit
403
526
  topics
404
527
  end
405
528
 
529
+ ##
530
+ ## Read build note and include upstream topics
531
+ ##
532
+ ## @param path [String] The build note path
533
+ ##
406
534
  def read_help(path = nil)
407
535
  @topics = read_help_file(path)
408
536
  return unless path.nil? && Howzit.options[:include_upstream]
@@ -412,8 +540,17 @@ module Howzit
412
540
  upstream_topics.each do |topic|
413
541
  @topics.push(topic) unless find_topic(title.sub(/^.+:/, '')).count.positive?
414
542
  end
543
+
544
+ if note_file && @topics.empty?
545
+ Howzit.console.error("{br}Note file found but no topics detected in #{note_file}{x}".c)
546
+ Process.exit 1
547
+ end
548
+
415
549
  end
416
550
 
551
+ ##
552
+ ## Open build note in editor
553
+ ##
417
554
  def edit_note
418
555
  editor = Howzit.options.fetch(:editor, ENV['EDITOR'])
419
556
 
@@ -431,7 +568,16 @@ module Howzit
431
568
  end
432
569
  end
433
570
 
434
- def process_topic(topic, run, single = false)
571
+ ##
572
+ ## Run or print a topic
573
+ ##
574
+ ## @param topic [Topic] The topic
575
+ ## @param run [Boolean] execute directives if
576
+ ## true
577
+ ## @param single [Boolean] is being output as a
578
+ ## single topic
579
+ ##
580
+ def process_topic(topic, run, single: false)
435
581
  new_topic = topic.dup
436
582
 
437
583
  # Handle variable replacement
@@ -445,6 +591,9 @@ module Howzit
445
591
  output.nil? ? '' : output.join("\n")
446
592
  end
447
593
 
594
+ ##
595
+ ## Search and process the build note
596
+ ##
448
597
  def process
449
598
  output = []
450
599
 
@@ -537,10 +686,10 @@ module Howzit
537
686
 
538
687
  if !topic_matches.empty?
539
688
  # If we found a match
540
- topic_matches.each { |topic_match| output.push(process_topic(topic_match, Howzit.options[:run], true)) }
689
+ topic_matches.each { |topic_match| output.push(process_topic(topic_match, Howzit.options[:run], single: true)) }
541
690
  else
542
691
  # If there's no argument or no match found, output all
543
- topics.each { |k| output.push(process_topic(k, false, false)) }
692
+ topics.each { |k| output.push(process_topic(k, false, single: false)) }
544
693
  end
545
694
  Howzit.options[:paginate] = false if Howzit.options[:run]
546
695
  Util.show(output.join("\n").strip, Howzit.options)
data/lib/howzit/colors.rb CHANGED
@@ -4,7 +4,9 @@
4
4
  module Howzit
5
5
  # Terminal output color functions.
6
6
  module Color
7
+ # Regexp to match excape sequences
7
8
  ESCAPE_REGEX = /(?<=\[)(?:(?:(?:[349]|10)[0-9]|[0-9])?;?)+(?=m)/.freeze
9
+
8
10
  # All available color names. Available as methods and string extensions.
9
11
  #
10
12
  # @example Use a color as a method. Color reset will be added to end of string.
@@ -79,6 +81,7 @@ module Howzit
79
81
  [:default, '0;39']
80
82
  ].map(&:freeze).freeze
81
83
 
84
+ # Array of attribute keys only
82
85
  ATTRIBUTE_NAMES = ATTRIBUTES.transpose.first
83
86
 
84
87
  # Returns true if Howzit::Color supports the +feature+.
@@ -1,5 +1,6 @@
1
1
  # frozen_string_literal: true
2
2
 
3
+ # Available log levels
3
4
  LOG_LEVELS = {
4
5
  debug: 0,
5
6
  info: 1,
data/lib/howzit/hash.rb CHANGED
@@ -41,7 +41,7 @@ class ::Hash
41
41
  end
42
42
 
43
43
  def stringify_keys!
44
- replace stringify_keys
44
+ replace stringify_keys
45
45
  end
46
46
 
47
47
  # Turn all keys into symbols
@@ -50,6 +50,6 @@ class ::Hash
50
50
  end
51
51
 
52
52
  def symbolize_keys!
53
- replace symbolize_keys
53
+ replace symbolize_keys
54
54
  end
55
55
  end
data/lib/howzit/task.rb CHANGED
@@ -1,6 +1,7 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Howzit
4
+ # Task object
4
5
  class Task
5
6
  attr_reader :type, :title, :action, :parent, :optional, :default
6
7
 
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.9'
6
+ VERSION = '2.0.10'
7
7
  end
data/lib/howzit.rb CHANGED
@@ -24,11 +24,22 @@ require 'tty/screen'
24
24
  require 'tty/box'
25
25
  # require 'tty/prompt'
26
26
 
27
+ # Main config dir
27
28
  CONFIG_DIR = '~/.config/howzit'
29
+
30
+ # Config file name
28
31
  CONFIG_FILE = 'howzit.yaml'
32
+
33
+ # Ignore file name
29
34
  IGNORE_FILE = 'ignore.yaml'
35
+
36
+ # Available options for matching method
30
37
  MATCHING_OPTIONS = %w[partial exact fuzzy beginswith].freeze
38
+
39
+ # Available options for multiple_matches method
31
40
  MULTIPLE_OPTIONS = %w[first best all choose].freeze
41
+
42
+ # Available options for header formatting
32
43
  HEADER_FORMAT_OPTIONS = %w[border block].freeze
33
44
 
34
45
  # Main module for howzit
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: howzit
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.9
4
+ version: 2.0.10
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -297,7 +297,6 @@ files:
297
297
  - lib/.rubocop.yml
298
298
  - lib/howzit.rb
299
299
  - lib/howzit/buildnote.rb
300
- - lib/howzit/buildnotes.rb
301
300
  - lib/howzit/colors.rb
302
301
  - lib/howzit/config.rb
303
302
  - lib/howzit/console_logger.rb