run_kit 0.1.2 → 0.1.3

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: 6dabac9fceff597dbc18cca5e813a37c784bce2ed1148425ad5fd82264a2e3bd
4
- data.tar.gz: f544b871ca35c2da4fd965b017a9e2b11c052f99d755c92b6110e4113ec25a4f
3
+ metadata.gz: 1876301102a9221f5207f024bcd108a95d3547cf96d270f475700959d8209cb6
4
+ data.tar.gz: b21d96ce661cbe5e45f2de8b6bf9cb1718d2bb7305bce4e15773aa7a9c4882e2
5
5
  SHA512:
6
- metadata.gz: 2e56df9f10755fec5eadc44396f368c0f6ebadd9987b2cf317373129902264c2e40073000198dba0511e142082780c0176a677461cd4fac083cd18d9dd8c2e29
7
- data.tar.gz: b9dbdf57d9ec47c482f1dcdf23b237287564fe6b5c3568b2cdd1185d6ea893aee37b48634bd507e773d6deeb75d1234f54c522f9250e0ed8f348d8e17c9c424f
6
+ metadata.gz: a82974e7beaa687457ff4b8555e8d1b38a284c89d4ef756755bbccc92c16ff857cdfe9d5083620bb53265d6b04de43d7fdca168559c4bef25ef99c052e98fbae
7
+ data.tar.gz: 43946b37bb5f6a155b5eb2d27220afa96df7705827db9e0a7ddb4aa5b86f6234629908436cdd288ed20cc8b751c48c413f3441d265cf4c8925de373629f7e99f
data/.rubocop.yml CHANGED
@@ -35,7 +35,6 @@ Naming/MemoizedInstanceVariableName: { Enabled: true } # clean memo ivars
35
35
  Naming/MethodName: { Enabled: true } # keep method names conventional
36
36
  Performance/MapCompact: { Enabled: true } # filter_map-ish style
37
37
  Performance/RegexpMatch: { Enabled: false } # local style is fine
38
- Performance/SelectMap: { Enabled: true } # filter_map-ish style
39
38
  Style/BlockDelimiters: { Enabled: true } # do/end vs braces
40
39
  Style/ClassAndModuleChildren: { Enabled: true, EnforcedStyle: nested } # explicit nesting
41
40
  Style/ClassMethodsDefinitions: { Enabled: true } # avoid "class << self"
data/README.md CHANGED
@@ -111,6 +111,10 @@ Note: There has been some effort to get the Pathname helpers into Ruby itself, w
111
111
 
112
112
  ### Changelog
113
113
 
114
+ #### 0.1.3 (Sep 2026)
115
+
116
+ - move PROGBAR constant into RunKit::
117
+
114
118
  #### 0.1.2 (Sep 2026)
115
119
 
116
120
  - allow options to read from ENV
@@ -34,20 +34,15 @@ module RunKit
34
34
  # each.with_progresbar
35
35
  module Enumerator
36
36
  def with_progressbar(options = {}, &block)
37
- defaults = {
38
- format: "%t: %j%% %B #{RunKit::Term.paint_ansi("%c/%u %e", RunKit::Term.ansi256_fg(242))}",
39
- progress_mark: RunKit::Term.paint_ansi("━", RunKit::Term.ansi256_fg(46)),
40
- remainder_mark: RunKit::Term.paint_ansi("━", RunKit::Term.ansi256_fg(237)),
37
+ options = RunKit::PROGRESSBAR.merge(
41
38
  output: $stdout.isatty ? $stdout : $stderr,
42
- total: size,
43
- length: 72,
44
- }
45
- options = defaults.merge(options)
39
+ total: size
40
+ ).merge(options)
46
41
 
47
42
  return enum_for(__method__) if !block
48
43
 
49
- if !options[:hide]
50
- bar = ProgressBar.create(options)
44
+ bar = if !options[:hide]
45
+ ProgressBar.create(options)
51
46
  end
52
47
  RunKit::Term.with_hidden_cursor(options[:output]) do
53
48
  each do
@@ -6,7 +6,7 @@
6
6
  module RunKit
7
7
  module Options
8
8
  class Parser
9
- attr_reader :config, :options, :queue
9
+ attr_reader :config
10
10
 
11
11
  def initialize(config)
12
12
  @config = config
@@ -14,12 +14,24 @@ module RunKit
14
14
 
15
15
  # Reset transient state, parse argv, and assemble the result.
16
16
  def parse(argv)
17
- env = build_env
18
- raise NakedRequested if config.naked? && argv.empty? && env.empty?
17
+ # 1. naked?
18
+ raise NakedRequested if config.naked? && argv.empty?
19
+
20
+ # 2. Parse argv. We do this first, because other things can raise and
21
+ # --help should trump other issues.
22
+ argv_options = parse_argv(argv)
23
+
24
+ # 3. defaults => ENV => ARGV
25
+ options = {}.merge(config.defaults, parse_env, argv_options)
26
+
27
+ # 4. validate final options
28
+ validate!(options)
29
+
30
+ # success! add predicate? keys
31
+ config.flags.select(&:bool?).map(&:key).each do
32
+ options[:"#{_1}?"] = options[_1] if options.key?(_1)
33
+ end
19
34
 
20
- @options, @queue = config.defaults.merge(env), argv.dup
21
- parse_queue
22
- validate!
23
35
  options
24
36
  end
25
37
 
@@ -29,40 +41,36 @@ module RunKit
29
41
  # main parser
30
42
  #
31
43
 
32
- def parse_queue
33
- # any non-flags we find below
34
- operands = []
35
-
36
- # process argv as queue
37
- while (item = queue.shift)
38
- case item
39
- when Flag::SWITCH_RE, Flag::INLINE_RE then parse_switch(item, Regexp.last_match)
40
- when /\A-[^-]/ then parse_smashed(item)
41
- when "", /\A[^-]/ then operands << item
42
- when "--" then break operands.concat(queue)
43
- else; raise Error, "unexpected argument '#{item}' found"
44
+ def parse_argv(argv)
45
+ {}.tap do |result|
46
+ # any non-flags we find below
47
+ operands = []
48
+
49
+ # process argv as queue
50
+ queue = argv.dup
51
+ while (item = queue.shift)
52
+ case item
53
+ when Flag::SWITCH_RE, Flag::INLINE_RE then result.merge!(parse_switch(item, Regexp.last_match, queue))
54
+ when /\A-[^-]/ then result.merge!(parse_smashed(item, queue))
55
+ when "", /\A[^-]/ then operands << item
56
+ when "--" then break operands.concat(queue)
57
+ else; raise Error, "unexpected argument '#{item}' found"
58
+ end
44
59
  end
45
- end
46
60
 
47
- # add pred? for bools
48
- config.flags.filter_map { _1.key if _1.bool? }.each do
49
- options[:"#{_1}?"] = options[_1] if options.key?(_1)
50
- end
61
+ # positionals
62
+ config.positionals.each { result[_1.key] = operands.shift }
51
63
 
52
- # positionals
53
- config.positionals.each do
54
- options[_1.key] = operands.shift
64
+ # _args
65
+ result[:_args] = operands
55
66
  end
56
-
57
- # _args
58
- options[:_args] = operands
59
67
  end
60
68
 
61
69
  #
62
70
  # -x or -x=123 or --xyz or --xyz=123 or --no-xyz
63
71
  #
64
72
 
65
- def parse_switch(item, match)
73
+ def parse_switch(item, match, queue)
66
74
  switch = "-#{match[1]}"
67
75
  param = match[2]
68
76
  separator = param ? "=" : ""
@@ -71,15 +79,13 @@ module RunKit
71
79
  if (flag = config.flag(switch))
72
80
  builtin!(flag)
73
81
  param = queue.shift if flag.takes_param? && separator.empty?
74
- options[flag.key] = flag.parse(switch, param)
75
- return
82
+ return {flag.key => flag.parse(switch, param)}
76
83
  end
77
84
 
78
85
  # --no-xyz?
79
86
  if (neg = find_negated_flag(switch))
80
87
  raise Error, "option '#{item}' does not take a value" if separator == "="
81
- options[neg.key] = false
82
- return
88
+ return {neg.key => false}
83
89
  end
84
90
 
85
91
  raise Error, "unexpected argument '#{item}' found"
@@ -91,7 +97,8 @@ module RunKit
91
97
 
92
98
  # Expand short-switch groups such as `-qv`. A parameter-taking switch ends
93
99
  # the group and consumes either its attached suffix or the next queue item.
94
- def parse_smashed(group)
100
+ def parse_smashed(group, queue)
101
+ result = {}
95
102
  (1...group.length).each do |idx|
96
103
  switch = "-#{group[idx]}"
97
104
  flag = config.flag(switch)
@@ -105,26 +112,30 @@ module RunKit
105
112
  else
106
113
  queue.shift
107
114
  end
108
- options[flag.key] = flag.parse(switch, param)
109
- return
115
+ result[flag.key] = flag.parse(switch, param)
116
+ return result
110
117
  end
111
118
 
112
119
  # bool
113
- options[flag.key] = true
120
+ result[flag.key] = true
114
121
  end
122
+ result
115
123
  end
116
124
 
117
125
  #
118
- # helpers
126
+ # env
119
127
  #
120
128
 
121
- def build_env
122
- config.flags.filter_map do
123
- next unless _1.env && ENV.key?(_1.env)
124
- [_1.key, _1.parse_env(ENV.fetch(_1.env))]
129
+ def parse_env
130
+ config.flags.select { _1.env && ENV.key?(_1.env) }.map do |flag|
131
+ [flag.key, flag.parse_env(ENV[flag.env])]
125
132
  end.to_h
126
133
  end
127
134
 
135
+ #
136
+ # helpers
137
+ #
138
+
128
139
  def builtin!(flag)
129
140
  raise HelpRequested if flag == config.help_flag
130
141
  raise VersionRequested if flag == config.version_flag
@@ -137,7 +148,7 @@ module RunKit
137
148
  end
138
149
  end
139
150
 
140
- def validate!
151
+ def validate!(options)
141
152
  config.required.each do
142
153
  raise Error, "required option '#{_1.switch}' is missing" if !options.key?(_1.key)
143
154
  end
data/lib/run_kit.rb CHANGED
@@ -16,7 +16,14 @@ require_relative "run_kit/term"
16
16
  require_relative "run_kit/options"
17
17
  require_relative "run_kit/shell"
18
18
 
19
- # handy entry point for RunKit::Options
20
19
  module RunKit
20
+ PROGRESSBAR = {
21
+ format: "%t: %j%% %B #{Term.paint_ansi("%c/%u %e", Term.ansi256_fg(242))}",
22
+ progress_mark: Term.paint_ansi("━", Term.ansi256_fg(46)),
23
+ remainder_mark: Term.paint_ansi("━", Term.ansi256_fg(237)),
24
+ length: 72,
25
+ }
26
+
27
+ # handy entry point for RunKit::Options
21
28
  def self.parse(...) = Options.parse(...)
22
29
  end
data/run_kit.gemspec CHANGED
@@ -1,6 +1,6 @@
1
1
  Gem::Specification.new do |s|
2
2
  s.name = "run_kit"
3
- s.version = "0.1.2"
3
+ s.version = "0.1.3"
4
4
  s.authors = ["Adam Doppelt"]
5
5
  s.email = "amd@gurge.com"
6
6
  s.summary = "Run kit."
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: run_kit
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Adam Doppelt
@@ -87,7 +87,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
87
87
  - !ruby/object:Gem::Version
88
88
  version: '0'
89
89
  requirements: []
90
- rubygems_version: 4.0.6
90
+ rubygems_version: 3.6.9
91
91
  specification_version: 4
92
92
  summary: Run kit.
93
93
  test_files: []