howzit 2.0.5 → 2.0.8

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: 95a5f6c56ebff1fb944ca8ea23cba45ca5b71647654a315fd2cf7e486d522309
4
- data.tar.gz: f9ac61f6fad2aff412d4302d0c586e9b287f284659255215a9565c8632bdfc8c
3
+ metadata.gz: a199c0d74513fee2be1dcd71390927d7776cecf50bd6b075504f9ed82fc548b0
4
+ data.tar.gz: d3668793cf618dc1d785cab3a7c87b93c3f5cc4edc546ab20b0c10de8986f7a1
5
5
  SHA512:
6
- metadata.gz: be7ac525fc55a0e199b5762830bd0c6ef41b0b099627a45f1ca2aacd4508df3574f06e803513a22d870985631520c58b7f75c9e8519b5b02cf274eaeec577d56
7
- data.tar.gz: e60252f5081ae563fc7eb8c207bb6ba0674b316455247cbc886e1b386dd33ecef234cfa493c6453bc02403daa11f79afb5f514c95a2f4e080302010466a7d4a6
6
+ metadata.gz: cdc109a75df7f9757c3870092b3d3550dba228d4ddc9ff0d58befc5cb1174676808f4a29c8e0805b3e5150bf2c425b8f1d5ccebef226b6fffc96085562094f07
7
+ data.tar.gz: 394947ec4f9a437af899a4806e2daa60a1ffbd040785ff249dffe258030e88426a594a0b1afbea413839a72173daaf4cfbda4ef8643049296627c7928677fd68
data/CHANGELOG.md CHANGED
@@ -1,3 +1,27 @@
1
+ ### 2.0.8
2
+
3
+ 2022-08-04 13:28
4
+
5
+ #### FIXED
6
+
7
+ - Bugfixes
8
+
9
+ ### 2.0.7
10
+
11
+ 2022-08-04 13:04
12
+
13
+ #### NEW
14
+
15
+ - --debug flag (shortcut for :log_level: 0)
16
+
17
+ #### IMPROVED
18
+
19
+ - Console output now gets log levels, so :log_level: config option and --quiet/verbose have more utility
20
+
21
+ ### 2.0.6
22
+
23
+ 2022-08-04 11:08
24
+
1
25
  ### 2.0.5
2
26
 
3
27
  2022-08-04 10:50
data/README.md CHANGED
@@ -273,17 +273,21 @@ Some of the command line options can be set as defaults. The first time you run
273
273
 
274
274
  ---
275
275
  :color: true
276
+ :config_editor: subl
277
+ :editor: subl
278
+ :header_format: block
276
279
  :highlight: true
277
- :paginate: true
278
- :wrap: 80
280
+ :highlighter: mdcat
281
+ :include_upstream: true
282
+ :log_level: 0
283
+ :matching: fuzzy
284
+ :multiple_matches: choose
279
285
  :output_title: false
280
- :highlighter: auto
281
286
  :pager: auto
282
- :matching: partial
283
- :include_upstream: false
284
- :log_level: 1
285
- :multiple_matches: choose
286
- :header_format: border
287
+ :paginate: true
288
+ :show_all_code: false
289
+ :show_all_on_error: false
290
+ :wrap: 0
287
291
 
288
292
  If `:color:` is false, output will not be colored, and markdown highlighting will be bypassed.
289
293
 
@@ -354,6 +358,12 @@ If set to `auto` howzit will look for markdown highlighters in this order, using
354
358
 
355
359
  If you're combining a highlighter with howzit's pagination, include any flags needed to disable the highlighter's pagination (e.g. `mdless --no-pager`).
356
360
 
361
+ ### Configuring from the Command Line
362
+
363
+ You can get and set config options from the command line using `--config-get` and `--config-set`. If you run `--config-get` with no argument, it will display all config options. If you add a key (exact match required) you can get just the value for that key.
364
+
365
+ Using `--config-set` requires an argument in the format `key=value`. The type of the value (boolean, integer, string, symbol) will be automatically determined and converted. To change your highlighter, for example, use `howzit --config-set highlighter=mdcat`.
366
+
357
367
  ## Shell Integration
358
368
 
359
369
  I personally like to alias `bld` to `howzit -r`. If you define a function in your shell, you can have it default to "build" but accept an alternate argument. There's an example for Fish included, and in Bash it would be as simple as `howzit -r ${1:build}`.
data/bin/howzit CHANGED
@@ -74,11 +74,18 @@ OptionParser.new do |opts|
74
74
  end
75
75
 
76
76
  opts.on('-q', '--quiet', 'Silence info message') do
77
- Howzit.options[:log_level] = 3
77
+ Howzit.options[:log_level] = 4
78
+ Howzit.console.reset_level
78
79
  end
79
80
 
80
81
  opts.on('-v', '--verbose', 'Show all messages') do
82
+ Howzit.options[:log_level] = 1
83
+ Howzit.console.reset_level
84
+ end
85
+
86
+ opts.on('-d', '--debug', 'Show debug messages (and all messages)') do
81
87
  Howzit.options[:log_level] = 0
88
+ Howzit.console.reset_level
82
89
  end
83
90
 
84
91
  opts.on('-u', '--[no-]upstream', 'Traverse up parent directories for additional build notes') do |p|
@@ -114,8 +121,8 @@ OptionParser.new do |opts|
114
121
  raise 'Argument must be KEY=VALUE' unless key =~ /\S=\S/
115
122
 
116
123
  parts = key.split(/=/)
117
- k = parts[0].sub(/^:/, '')
118
- v = parts[1..].join(' ')
124
+ k = parts.shift.sub(/^:/, '')
125
+ v = parts.join(' ')
119
126
 
120
127
  if Howzit.options.key?(k.to_sym)
121
128
  Howzit.options[k.to_sym] = v.to_config_value(Howzit.options[k.to_sym])
@@ -89,7 +89,7 @@ module Howzit
89
89
  # Create a buildnotes skeleton
90
90
  def create_note
91
91
  trap('SIGINT') do
92
- warn "\nCanceled"
92
+ Howzit.console.info "\nCanceled"
93
93
  exit!
94
94
  end
95
95
  default = !$stdout.isatty || Howzit.options[:default]
@@ -269,8 +269,8 @@ module Howzit
269
269
  required = t_meta['required'].strip.split(/\s*,\s*/)
270
270
  required.each do |req|
271
271
  unless @metadata.keys.include?(req.downcase)
272
- warn %({xr}ERROR: Missing required metadata key from template '{bw}#{File.basename(template, '.md')}{xr}'{x}).c
273
- warn %({xr}Please define {by}#{req.downcase}{xr} in build notes{x}).c
272
+ Howzit.console.error %({xr}ERROR: Missing required metadata key from template '{bw}#{File.basename(template, '.md')}{xr}'{x}).c
273
+ Howzit.console.error %({xr}Please define {by}#{req.downcase}{xr} in build notes{x}).c
274
274
  Process.exit 1
275
275
  end
276
276
  end
data/lib/howzit/config.rb CHANGED
@@ -22,14 +22,27 @@ module Howzit
22
22
  wrap: 0
23
23
  }.deep_freeze
24
24
 
25
+ ##
26
+ ## Initialize a config object
27
+ ##
25
28
  def initialize
26
29
  load_options
27
30
  end
28
31
 
32
+ ##
33
+ ## Write a config to a file
34
+ ##
35
+ ## @param config The configuration
36
+ ##
29
37
  def write_config(config)
30
38
  File.open(config_file, 'w') { |f| f.puts config.to_yaml }
31
39
  end
32
40
 
41
+ ##
42
+ ## Test if a file should be ignored based on YAML file
43
+ ##
44
+ ## @param filename The filename to test
45
+ ##
33
46
  def should_ignore(filename)
34
47
  return false unless File.exist?(ignore_file)
35
48
 
@@ -47,10 +60,18 @@ module Howzit
47
60
  ignore
48
61
  end
49
62
 
63
+ ##
64
+ ## Find the template folder
65
+ ##
66
+ ## @return [String] path to template folder
67
+ ##
50
68
  def template_folder
51
69
  File.join(config_dir, 'templates')
52
70
  end
53
71
 
72
+ ##
73
+ ## Initiate the editor for the config
74
+ ##
54
75
  def editor
55
76
  edit_config(DEFAULTS)
56
77
  end
@@ -91,12 +112,12 @@ module Howzit
91
112
 
92
113
  def create_config(d)
93
114
  unless File.directory?(config_dir)
94
- warn "Creating config directory at #{config_dir}"
115
+ Howzit::ConsoleLogger.new(1).info "Creating config directory at #{config_dir}"
95
116
  FileUtils.mkdir_p(config_dir)
96
117
  end
97
118
 
98
119
  unless File.exist?(config_file)
99
- warn "Writing fresh config file to #{config_file}"
120
+ Howzit::ConsoleLogger.new(1).info "Writing fresh config file to #{config_file}"
100
121
  write_config(d)
101
122
  end
102
123
  config_file
@@ -0,0 +1,43 @@
1
+ # frozen_string_literal: true
2
+
3
+ LOG_LEVELS = {
4
+ debug: 0,
5
+ info: 1,
6
+ warn: 2,
7
+ error: 3
8
+ }.deep_freeze
9
+
10
+ module Howzit
11
+ # Console logging
12
+ class ConsoleLogger
13
+ attr_accessor :log_level
14
+
15
+ def initialize(level = nil)
16
+ @log_level = level.to_i || Howzit.options[:log_level]
17
+ end
18
+
19
+ def reset_level
20
+ @log_level = Howzit.options[:log_level]
21
+ end
22
+
23
+ def write(msg, level = :info)
24
+ $stderr.puts msg if LOG_LEVELS[level] >= @log_level
25
+ end
26
+
27
+ def debug(msg)
28
+ write msg, :debug
29
+ end
30
+
31
+ def info(msg)
32
+ write msg, :info
33
+ end
34
+
35
+ def warn(msg)
36
+ write msg, :warn
37
+ end
38
+
39
+ def error(msg)
40
+ write msg, :error
41
+ end
42
+ end
43
+ end
data/lib/howzit/prompt.rb CHANGED
@@ -54,7 +54,7 @@ module Howzit
54
54
  ]
55
55
  res = `echo #{Shellwords.escape(matches.join("\n"))} | fzf #{settings.join(' ')}`.strip
56
56
  if res.nil? || res.empty?
57
- warn 'Cancelled'
57
+ Howzit.console.info 'Cancelled'
58
58
  Process.exit 0
59
59
  end
60
60
  return res.split(/\n/)
data/lib/howzit/task.rb CHANGED
@@ -13,6 +13,10 @@ module Howzit
13
13
  @default = default
14
14
  end
15
15
 
16
+ def inspect
17
+ %(<#Howzit::Task @type=:#{@type} @title="#{@title}" @block?=#{@action.split(/\n/).count > 1}>)
18
+ end
19
+
16
20
  def to_s
17
21
  @title
18
22
  end
data/lib/howzit/topic.rb CHANGED
@@ -42,7 +42,7 @@ module Howzit
42
42
  end
43
43
 
44
44
  if task.type == :block
45
- warn "{bg}Running block {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
45
+ Howzit.console.info "{bg}Running block {bw}#{title}{x}".c if Howzit.options[:log_level] < 2
46
46
  block = task.action
47
47
  script = Tempfile.new('howzit_script')
48
48
  begin
@@ -81,7 +81,7 @@ module Howzit
81
81
  end
82
82
  end
83
83
  else
84
- warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
84
+ Howzit.console.warn "{r}--run: No {br}@directive{xr} found in {bw}#{@title}{x}".c
85
85
  end
86
86
  output.push("{bm}Ran #{tasks} #{tasks == 1 ? 'task' : 'tasks'}{x}".c) if Howzit.options[:log_level] < 2 && !nested
87
87
 
@@ -95,21 +95,21 @@ module Howzit
95
95
  out = "{bg}Copying {bw}#{string}".c
96
96
  case os
97
97
  when /darwin.*/i
98
- warn "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
98
+ $stderr.puts "#{out} (macOS){x}".c if Howzit.options[:log_level].zero?
99
99
  `echo #{Shellwords.escape(string)}'\\c'|pbcopy`
100
100
  when /mingw|mswin/i
101
- warn "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
101
+ $stderr.puts "#{out} (Windows){x}".c if Howzit.options[:log_level].zero?
102
102
  `echo #{Shellwords.escape(string)} | clip`
103
103
  else
104
104
  if 'xsel'.available?
105
- warn "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level] < 2
105
+ $stderr.puts "#{out} (Linux, xsel){x}".c if Howzit.options[:log_level].zero?
106
106
  `echo #{Shellwords.escape(string)}'\\c'|xsel -i`
107
107
  elsif 'xclip'.available?
108
- warn "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level] < 2
108
+ $stderr.puts "#{out} (Linux, xclip){x}".c if Howzit.options[:log_level].zero?
109
109
  `echo #{Shellwords.escape(string)}'\\c'|xclip -i`
110
110
  else
111
- warn out if Howzit.options[:log_level] < 2
112
- warn 'Unable to determine executable for clipboard.'
111
+ $stderr.puts out if Howzit.options[:log_level].zero?
112
+ $stderr.puts 'Unable to determine executable for clipboard.'
113
113
  end
114
114
  end
115
115
  end
@@ -119,18 +119,18 @@ module Howzit
119
119
  out = "{bg}Opening {bw}#{command}".c
120
120
  case os
121
121
  when /darwin.*/i
122
- warn "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
122
+ Howzit.console.debug "#{out} (macOS){x}".c if Howzit.options[:log_level] < 2
123
123
  `open #{Shellwords.escape(command)}`
124
124
  when /mingw|mswin/i
125
- warn "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
125
+ Howzit.console.debug "#{out} (Windows){x}".c if Howzit.options[:log_level] < 2
126
126
  `start #{Shellwords.escape(command)}`
127
127
  else
128
128
  if 'xdg-open'.available?
129
- warn "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
129
+ Howzit.console.debug "#{out} (Linux){x}".c if Howzit.options[:log_level] < 2
130
130
  `xdg-open #{Shellwords.escape(command)}`
131
131
  else
132
- warn out if Howzit.options[:log_level] < 2
133
- warn 'Unable to determine executable for `open`.'
132
+ Howzit.console.debug out if Howzit.options[:log_level] < 2
133
+ Howzit.console.debug 'Unable to determine executable for `open`.'
134
134
  end
135
135
  end
136
136
  end
data/lib/howzit/util.rb CHANGED
@@ -40,7 +40,7 @@ module Howzit
40
40
  if hl.available?
41
41
  Howzit.options[:highlighter]
42
42
  else
43
- warn Color.template("{Rw}Error:{xbw} Specified highlighter (#{Howzit.options[:highlighter]}) not found, switching to auto")
43
+ Howzit.console.error Color.template("{Rw}Error:{xbw} Specified highlighter (#{Howzit.options[:highlighter]}) not found, switching to auto")
44
44
  Howzit.options[:highlighter] = 'auto'
45
45
  which_highlighter
46
46
  end
@@ -78,7 +78,7 @@ module Howzit
78
78
  if pg.available?
79
79
  Howzit.options[:pager]
80
80
  else
81
- warn Color.template("{Rw}Error:{xbw} Specified pager (#{Howzit.options[:pager]}) not found, switching to auto")
81
+ Howzit.console.error Color.template("{Rw}Error:{xbw} Specified pager (#{Howzit.options[:pager]}) not found, switching to auto")
82
82
  Howzit.options[:pager] = 'auto'
83
83
  which_pager
84
84
  end
@@ -104,7 +104,7 @@ module Howzit
104
104
  begin
105
105
  exec(pager)
106
106
  rescue SystemCallError => e
107
- @log.error(e)
107
+ Howzit.console.error(e)
108
108
  exit 1
109
109
  end
110
110
  end
@@ -3,5 +3,5 @@
3
3
  # Primary module for this gem.
4
4
  module Howzit
5
5
  # Current Howzit version.
6
- VERSION = '2.0.5'
6
+ VERSION = '2.0.8'
7
7
  end
data/lib/howzit.rb CHANGED
@@ -5,8 +5,9 @@ require_relative 'howzit/prompt'
5
5
  require_relative 'howzit/colors'
6
6
  require_relative 'howzit/stringutils'
7
7
 
8
- require_relative 'howzit/util'
9
8
  require_relative 'howzit/hash'
9
+ require_relative 'howzit/console_logger'
10
+ require_relative 'howzit/util'
10
11
  require_relative 'howzit/config'
11
12
  require_relative 'howzit/task'
12
13
  require_relative 'howzit/topic'
@@ -52,5 +53,9 @@ module Howzit
52
53
  def buildnote
53
54
  @buildnote ||= BuildNote.new
54
55
  end
56
+
57
+ def console
58
+ @console ||= Howzit::ConsoleLogger.new(options[:log_level])
59
+ end
55
60
  end
56
61
  end
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.5
4
+ version: 2.0.8
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brett Terpstra
@@ -272,6 +272,7 @@ files:
272
272
  - lib/howzit/buildnotes.rb
273
273
  - lib/howzit/colors.rb
274
274
  - lib/howzit/config.rb
275
+ - lib/howzit/console_logger.rb
275
276
  - lib/howzit/hash.rb
276
277
  - lib/howzit/prompt.rb
277
278
  - lib/howzit/stringutils.rb