l43_opt_parser 0.3.1 → 0.3.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 +4 -4
- data/lib/l43/opt_parser/description.rb +17 -6
- data/lib/l43/opt_parser/version.rb +1 -1
- data/lib/l43/opt_parser.rb +21 -11
- metadata +5 -5
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9943a421709cab1ad71863251775608917a07585be3d85a5546f34fdcfdb1c2b
|
|
4
|
+
data.tar.gz: cb1d8969b0a6566525bb1839b698c3683ce1628fef3130e333199e616aa87d93
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 4789ff24391f88adf83d2cd332eb3c92f8c51a76c66993a52f0fdc18e495ab58b8ec2923a74ca829a170fdeeebfb3f4ab7b07d636bdb4d272213fd68ce4f307a
|
|
7
|
+
data.tar.gz: 230337c7ce46e0b1956aef82b3520428c253824c8da3c2aad9ce047d829cc944bf1cb78b75035eaa15036a601909585566c834fd1c54aead48a4f61a20c047a9
|
|
@@ -1,21 +1,32 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'l43/simple_color/file_colorizer'
|
|
3
4
|
require 'l43/core/none'
|
|
5
|
+
require 'l43/core/forwarder'
|
|
4
6
|
module L43
|
|
5
7
|
class OptParser
|
|
6
8
|
class Description
|
|
9
|
+
extend Core::Forwarder
|
|
10
|
+
forward :xcolorize_file, to: L43::SimpleColor
|
|
7
11
|
|
|
8
12
|
def add_desc(*chunks, indent: 5)
|
|
9
13
|
self << [indent, *chunks]
|
|
10
14
|
end
|
|
11
15
|
|
|
12
|
-
def
|
|
16
|
+
def add_desc_from_file(file)
|
|
17
|
+
xcolorize_file(file).each do |colored, _|
|
|
18
|
+
_lines << colored
|
|
19
|
+
end
|
|
20
|
+
self
|
|
21
|
+
end
|
|
22
|
+
|
|
23
|
+
def add_flag(flag, indent: 4, color: :cyan)
|
|
13
24
|
return unless flag.desc
|
|
14
25
|
short = flag.short ? ":#{flag.short}|" : ""
|
|
15
26
|
self << [indent, color, short, ":", flag.name.to_s, :reset, 1, flag.desc ]
|
|
16
27
|
end
|
|
17
28
|
|
|
18
|
-
def add_kwd(kwd, indent:
|
|
29
|
+
def add_kwd(kwd, indent: 4, color: :cyan, vcolor: [:bold,:blue])
|
|
19
30
|
return unless kwd.desc
|
|
20
31
|
short = kwd.short ? "#{kwd.short}:|" : ""
|
|
21
32
|
default = kwd.default == Core::None ? [] : [1, :dim, "defaults to: ", :bold, kwd.default.inspect]
|
|
@@ -26,20 +37,20 @@ module L43
|
|
|
26
37
|
self << chunks
|
|
27
38
|
end
|
|
28
39
|
|
|
29
|
-
def add_section(text, indent:
|
|
40
|
+
def add_section(text, indent: 2, color: [:bold, :green])
|
|
30
41
|
self << [nil, indent, color, text]
|
|
31
42
|
end
|
|
32
43
|
|
|
33
44
|
def add_usage(name, options:, args:)
|
|
34
45
|
options = "options" if options == true
|
|
35
46
|
args = "args" if args == true
|
|
36
|
-
@__lines__ = [[:bold,
|
|
47
|
+
@__lines__ = [[:bold, "usage: ", :green, name, :reset, *_args(options, [:bold, :cyan]), *_args(args, [:bold, :blue], "...")], *_lines]
|
|
37
48
|
end
|
|
38
49
|
|
|
39
50
|
def lines = _lines.dup.freeze
|
|
40
51
|
|
|
41
52
|
private
|
|
42
|
-
def _args(args, cols, pfx='')
|
|
53
|
+
def _args(args, cols, pfx=' ')
|
|
43
54
|
case args
|
|
44
55
|
when nil
|
|
45
56
|
[]
|
|
@@ -54,7 +65,7 @@ module L43
|
|
|
54
65
|
|
|
55
66
|
|
|
56
67
|
def <<(*line)
|
|
57
|
-
_lines << [
|
|
68
|
+
_lines << [*line.flatten, :reset]
|
|
58
69
|
end
|
|
59
70
|
end
|
|
60
71
|
end
|
data/lib/l43/opt_parser.rb
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require 'l43/
|
|
4
|
-
require 'l43/
|
|
3
|
+
require 'l43/simple_color'
|
|
4
|
+
require 'l43/simple_color/file_colorizer'
|
|
5
5
|
require 'l43/core/none'
|
|
6
6
|
require 'l43/open_struct'
|
|
7
7
|
require 'l43/open_object'
|
|
@@ -16,7 +16,7 @@ require_relative 'opt_parser/meta'
|
|
|
16
16
|
module L43
|
|
17
17
|
class OptParser
|
|
18
18
|
|
|
19
|
-
include
|
|
19
|
+
include SimpleColor
|
|
20
20
|
include Core
|
|
21
21
|
include Memos
|
|
22
22
|
include Meta
|
|
@@ -77,12 +77,17 @@ module L43
|
|
|
77
77
|
self
|
|
78
78
|
end
|
|
79
79
|
|
|
80
|
-
def add_desc(*chunks)
|
|
81
|
-
|
|
80
|
+
def add_desc(*chunks, file: nil)
|
|
81
|
+
raise ArgumentError, "cannot use chunks and file" unless chunks.empty? || file.nil?
|
|
82
|
+
if file
|
|
83
|
+
description.add_desc_from_file(file)
|
|
84
|
+
else
|
|
85
|
+
description.add_desc(*chunks)
|
|
86
|
+
end
|
|
82
87
|
self
|
|
83
88
|
end
|
|
84
89
|
|
|
85
|
-
def section(line, indent:
|
|
90
|
+
def section(line, indent: 2, color: [:bold, :green])
|
|
86
91
|
description.add_section(line, indent:, color:)
|
|
87
92
|
self
|
|
88
93
|
end
|
|
@@ -91,7 +96,11 @@ module L43
|
|
|
91
96
|
# --------
|
|
92
97
|
|
|
93
98
|
def descriptions = description.lines
|
|
94
|
-
def help(device: $stderr)
|
|
99
|
+
def help(device: $stderr)
|
|
100
|
+
descriptions.each do
|
|
101
|
+
xputcol(it, device:)
|
|
102
|
+
end
|
|
103
|
+
end
|
|
95
104
|
|
|
96
105
|
|
|
97
106
|
# Business Logic
|
|
@@ -123,9 +132,10 @@ module L43
|
|
|
123
132
|
self
|
|
124
133
|
end
|
|
125
134
|
|
|
126
|
-
def usage(
|
|
127
|
-
description.add_usage(
|
|
135
|
+
def usage(*prefix, options: nil, args: nil, nls: 0)
|
|
136
|
+
description.add_usage(prefix, options:, args:)
|
|
128
137
|
nls.times { add_br }
|
|
138
|
+
self
|
|
129
139
|
end
|
|
130
140
|
|
|
131
141
|
private
|
|
@@ -258,7 +268,7 @@ module L43
|
|
|
258
268
|
|
|
259
269
|
def post_checks!(keywords)
|
|
260
270
|
checks.each do |name, check|
|
|
261
|
-
next if check.(keywords)
|
|
271
|
+
next if check.(keywords, args)
|
|
262
272
|
|
|
263
273
|
raise FailedCheck, "in postcheck #{name||check.source_location.join(":")}"
|
|
264
274
|
end
|
|
@@ -266,7 +276,7 @@ module L43
|
|
|
266
276
|
|
|
267
277
|
def run_hooks(keywords)
|
|
268
278
|
hooks.inject keywords do |k, hook|
|
|
269
|
-
hook.(k)
|
|
279
|
+
hook.(k, args)
|
|
270
280
|
end
|
|
271
281
|
end
|
|
272
282
|
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: l43_opt_parser
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.3.
|
|
4
|
+
version: 0.3.3
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-
|
|
10
|
+
date: 2026-06-06 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ostruct
|
|
@@ -24,19 +24,19 @@ dependencies:
|
|
|
24
24
|
- !ruby/object:Gem::Version
|
|
25
25
|
version: 0.6.3
|
|
26
26
|
- !ruby/object:Gem::Dependency
|
|
27
|
-
name:
|
|
27
|
+
name: l43_simple_color
|
|
28
28
|
requirement: !ruby/object:Gem::Requirement
|
|
29
29
|
requirements:
|
|
30
30
|
- - "~>"
|
|
31
31
|
- !ruby/object:Gem::Version
|
|
32
|
-
version: 0.
|
|
32
|
+
version: 0.2.2
|
|
33
33
|
type: :runtime
|
|
34
34
|
prerelease: false
|
|
35
35
|
version_requirements: !ruby/object:Gem::Requirement
|
|
36
36
|
requirements:
|
|
37
37
|
- - "~>"
|
|
38
38
|
- !ruby/object:Gem::Version
|
|
39
|
-
version: 0.
|
|
39
|
+
version: 0.2.2
|
|
40
40
|
- !ruby/object:Gem::Dependency
|
|
41
41
|
name: l43_core
|
|
42
42
|
requirement: !ruby/object:Gem::Requirement
|