l43_xargs 0.1.1 → 0.1.2
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/xargs/defined_args.rb +53 -9
- data/lib/l43/xargs/descriptions.rb +9 -2
- data/lib/l43/xargs/elements/common.rb +41 -0
- data/lib/l43/xargs/flag.rb +8 -13
- data/lib/l43/xargs/keyword.rb +7 -16
- data/lib/l43/xargs/parse.rb +1 -1
- data/lib/l43/xargs/version.rb +1 -1
- data/lib/l43/xargs.rb +19 -4
- metadata +3 -2
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 9ee664c6727ca6b0f9a4bc2b3ec2d4a8607ae71d4733ef95dc591de462fee198
|
|
4
|
+
data.tar.gz: a72496383d24e1e5435dab35ad246fd3deb28f9e945f48b220e98a764905e39d
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 01b48f90ba983ded2cd83df68a612bd69cf5001952bc7e1ff1e8553d3b4114a3276a12a13e326e369051ff4bff6925d0251864390ade9260c26128e9101de0fd
|
|
7
|
+
data.tar.gz: 3da5ad22c49ef316c735d52278aa2630b31a7b0c6e0f097ee981d656ff9e0ebdaee475b781603dbf06cf704e8d5964d991aea5414ee16fcda0202d5d03bb25b3
|
|
@@ -23,6 +23,15 @@ module L43
|
|
|
23
23
|
# p(defined_kwds: _defined_kwds)
|
|
24
24
|
end
|
|
25
25
|
|
|
26
|
+
def def_flag_alias(alias_name, flag_name)
|
|
27
|
+
case _check_for_duplicate(alias_name)
|
|
28
|
+
in nil
|
|
29
|
+
_add_flag_alias(alias_name, flag_name)
|
|
30
|
+
in data_name
|
|
31
|
+
raise DuplicateDefinition, "flag alias #{alias_name.inspect} fails as it is already used in #{data_name}"
|
|
32
|
+
end
|
|
33
|
+
end
|
|
34
|
+
|
|
26
35
|
def def_kwd(name, short=nil, desc:, default: None, &blk)
|
|
27
36
|
kwd = Keyword.new(name, short, desc:, default:, &blk)
|
|
28
37
|
_def_short_kwd(short, kwd) if short
|
|
@@ -30,13 +39,22 @@ module L43
|
|
|
30
39
|
# p(defined_kwds: _defined_kwds, defined_flags: _defined_flags)
|
|
31
40
|
end
|
|
32
41
|
|
|
42
|
+
def def_kwd_alias(alias_name, kwd_name)
|
|
43
|
+
case _check_for_duplicate(alias_name)
|
|
44
|
+
in nil
|
|
45
|
+
_add_kwd_alias(alias_name, kwd_name)
|
|
46
|
+
in data_name
|
|
47
|
+
raise DuplicateDefinition, "keyword alias #{alias_name.inspect} fails as it is already used in #{data_name}"
|
|
48
|
+
end
|
|
49
|
+
end
|
|
50
|
+
|
|
33
51
|
def get_element(name, &blk)
|
|
34
52
|
_defined_flags[name] ||
|
|
35
53
|
_defined_kwds.fetch(name, &blk)
|
|
36
54
|
end
|
|
37
55
|
|
|
38
56
|
def get_flag(long)
|
|
39
|
-
_defined_flags[long]
|
|
57
|
+
_defined_flags[long] || _flag_aliases[long]
|
|
40
58
|
end
|
|
41
59
|
|
|
42
60
|
def get_flags(&blk)
|
|
@@ -44,7 +62,7 @@ module L43
|
|
|
44
62
|
end
|
|
45
63
|
|
|
46
64
|
def get_kwd(long)
|
|
47
|
-
_defined_kwds[long]
|
|
65
|
+
_defined_kwds[long] || _kwd_aliases[long]
|
|
48
66
|
end
|
|
49
67
|
|
|
50
68
|
def get_kwds(&blk)
|
|
@@ -63,13 +81,6 @@ module L43
|
|
|
63
81
|
_defined_short_kwds[short]
|
|
64
82
|
end
|
|
65
83
|
|
|
66
|
-
def print_help(indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false, device: $stderr)
|
|
67
|
-
lines = help_description(indent:, newline:, program_name:, usage:, sections:, section_colors:)
|
|
68
|
-
lines.each do |line|
|
|
69
|
-
Output.putc(line, device:, indent:, colorize: @_colorize)
|
|
70
|
-
end
|
|
71
|
-
end
|
|
72
|
-
|
|
73
84
|
def args = @__args__ ||= []
|
|
74
85
|
|
|
75
86
|
def kwds = @__kwds__ ||= OpenStruct.new
|
|
@@ -79,6 +90,35 @@ module L43
|
|
|
79
90
|
@_colorize = colorize
|
|
80
91
|
end
|
|
81
92
|
|
|
93
|
+
def _add_flag_alias(alias_name, flag_name)
|
|
94
|
+
flag = _defined_flags.fetch(flag_name) do
|
|
95
|
+
raise BadDefinition, "flag alias from #{alias_name.inspect} to #{flag_name.inspect} fails as the destination is not a defined flag"
|
|
96
|
+
end
|
|
97
|
+
_flag_aliases.update(alias_name => flag)
|
|
98
|
+
flag.add_alias(alias_name)
|
|
99
|
+
end
|
|
100
|
+
|
|
101
|
+
def _add_kwd_alias(alias_name, kwd_name)
|
|
102
|
+
kwd = _defined_kwds.fetch(kwd_name) do
|
|
103
|
+
raise BadDefinition, "keyword alias from #{alias_name.inspect} to #{kwd_name.inspect} fails as the destination is not a defined keyword"
|
|
104
|
+
end
|
|
105
|
+
_kwd_aliases.update(alias_name => kwd)
|
|
106
|
+
kwd.add_alias(alias_name)
|
|
107
|
+
end
|
|
108
|
+
|
|
109
|
+
def _check_for_duplicate(name)
|
|
110
|
+
[[_defined_flags, "defined flags"],
|
|
111
|
+
[_defined_kwds, "defined keywords"],
|
|
112
|
+
[_defined_short_flags, "defined short flags"],
|
|
113
|
+
[_defined_short_kwds, "defined short keywords"],
|
|
114
|
+
[_flag_aliases, "defined flag aliases"],
|
|
115
|
+
[_kwd_aliases, "defined keyword aliases"],
|
|
116
|
+
].each do |data, data_name|
|
|
117
|
+
return data_name if data[name]
|
|
118
|
+
end
|
|
119
|
+
nil
|
|
120
|
+
end
|
|
121
|
+
|
|
82
122
|
def _colorize? = @_colorize
|
|
83
123
|
|
|
84
124
|
def _def_flag(name, flag)
|
|
@@ -108,6 +148,10 @@ module L43
|
|
|
108
148
|
def _defined_short_flags = @__defined_short_flags__ ||= OpenStruct.new
|
|
109
149
|
|
|
110
150
|
def _defined_short_kwds = @__defined_short_kwds__ ||= OpenStruct.new
|
|
151
|
+
|
|
152
|
+
def _flag_aliases = @___flag_aliases__ ||= Hash.new
|
|
153
|
+
|
|
154
|
+
def _kwd_aliases = @___kwd_aliases__ ||= Hash.new
|
|
111
155
|
end
|
|
112
156
|
end
|
|
113
157
|
end
|
|
@@ -3,7 +3,7 @@
|
|
|
3
3
|
module L43
|
|
4
4
|
class Xargs
|
|
5
5
|
module Descriptions
|
|
6
|
-
def help_description(indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false)
|
|
6
|
+
def help_description(lines = [],indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false)
|
|
7
7
|
flag_section =_section("Flags", indent:, newline:, sections:, section_colors:) unless _defined_flags.empty?
|
|
8
8
|
kwd_section = _section("Keywords", indent:, newline:, sections:, section_colors:) unless _defined_kwds.empty?
|
|
9
9
|
usage_section = [:bold, "usage: ", *_maybe_program_name(program_name), *_options(usage)] if usage
|
|
@@ -14,7 +14,14 @@ module L43
|
|
|
14
14
|
*_flag_descriptions,
|
|
15
15
|
kwd_section,
|
|
16
16
|
*_kwd_descriptions,
|
|
17
|
-
].compact
|
|
17
|
+
].compact + lines.map { [*it, :reset] }
|
|
18
|
+
end
|
|
19
|
+
|
|
20
|
+
def print_help(lines=[], indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false, device: $stderr)
|
|
21
|
+
lines = help_description(lines, indent:, newline:, program_name:, usage:, sections:, section_colors:)
|
|
22
|
+
lines.each do |line|
|
|
23
|
+
Output.putc(line, device:, indent:, colorize: @_colorize)
|
|
24
|
+
end
|
|
18
25
|
end
|
|
19
26
|
|
|
20
27
|
private
|
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
module L43
|
|
4
|
+
class Xargs
|
|
5
|
+
|
|
6
|
+
module Elements
|
|
7
|
+
module Common
|
|
8
|
+
attr_reader :additional_desc, :aliases,
|
|
9
|
+
:desc,
|
|
10
|
+
:name,
|
|
11
|
+
:short,
|
|
12
|
+
:value
|
|
13
|
+
|
|
14
|
+
def add_desc(desc)
|
|
15
|
+
@additional_desc << desc
|
|
16
|
+
end
|
|
17
|
+
|
|
18
|
+
def add_alias(alias_name) = aliases << alias_name
|
|
19
|
+
|
|
20
|
+
private
|
|
21
|
+
|
|
22
|
+
def _all_names(element_type)
|
|
23
|
+
case element_type
|
|
24
|
+
when :kwd
|
|
25
|
+
_get_all_names.map { "#{it}:" }.join("|")
|
|
26
|
+
when :flag
|
|
27
|
+
_get_all_names.map { ":#{it}" }.join("|")
|
|
28
|
+
else
|
|
29
|
+
raise ArgumentError, "element type was #{element_type.inspect} but only :flag and :kwd are supported"
|
|
30
|
+
end
|
|
31
|
+
end
|
|
32
|
+
|
|
33
|
+
def _get_all_names = [short, name, *aliases].compact
|
|
34
|
+
|
|
35
|
+
def aliases = @__aliases__ ||= []
|
|
36
|
+
|
|
37
|
+
end
|
|
38
|
+
end
|
|
39
|
+
end
|
|
40
|
+
end
|
|
41
|
+
# SPDX-License-Identifier: AGPL-3.0-or-later
|
data/lib/l43/xargs/flag.rb
CHANGED
|
@@ -1,21 +1,17 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'elements/common'
|
|
3
4
|
module L43
|
|
4
5
|
class Xargs
|
|
5
6
|
class Flag
|
|
7
|
+
include Elements::Common
|
|
8
|
+
|
|
6
9
|
attr_reader \
|
|
7
|
-
:
|
|
8
|
-
:desc,
|
|
9
|
-
:error,
|
|
10
|
-
:name,
|
|
11
|
-
:short,
|
|
12
|
-
:value
|
|
13
|
-
|
|
14
|
-
def add_desc(desc)
|
|
15
|
-
@additional_desc << desc
|
|
16
|
-
end
|
|
10
|
+
:error
|
|
17
11
|
|
|
18
12
|
def defaulted = !value
|
|
13
|
+
|
|
14
|
+
def description_name = _all_names(:flag)
|
|
19
15
|
|
|
20
16
|
def error? = !!@error
|
|
21
17
|
|
|
@@ -29,9 +25,7 @@ module L43
|
|
|
29
25
|
end
|
|
30
26
|
|
|
31
27
|
def name_description(colors: :cyan)
|
|
32
|
-
|
|
33
|
-
formatted_name = ":#{short}|#{formatted_name}" if short
|
|
34
|
-
[*Array(colors), formatted_name, :reset]
|
|
28
|
+
[*Array(colors), _all_names(:flag) + " ", :reset]
|
|
35
29
|
end
|
|
36
30
|
|
|
37
31
|
def set_error!(error) = @error = error
|
|
@@ -49,6 +43,7 @@ module L43
|
|
|
49
43
|
@short = short
|
|
50
44
|
@value = false
|
|
51
45
|
end
|
|
46
|
+
|
|
52
47
|
end
|
|
53
48
|
end
|
|
54
49
|
end
|
data/lib/l43/xargs/keyword.rb
CHANGED
|
@@ -1,29 +1,22 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require_relative 'elements/common'
|
|
3
4
|
module L43
|
|
4
5
|
class Xargs
|
|
5
6
|
class Keyword
|
|
7
|
+
include Elements::Common
|
|
8
|
+
|
|
6
9
|
CallbackError = Class.new(RuntimeError)
|
|
7
10
|
|
|
8
11
|
attr_reader \
|
|
9
|
-
:additional_desc,
|
|
10
12
|
:callback,
|
|
11
|
-
:default, :defaulted
|
|
12
|
-
:name,
|
|
13
|
-
:short,
|
|
14
|
-
:value
|
|
13
|
+
:default, :defaulted
|
|
15
14
|
|
|
16
|
-
def add_desc(desc)
|
|
17
|
-
@additional_desc << desc
|
|
18
|
-
end
|
|
19
|
-
|
|
20
|
-
def description_name
|
|
21
|
-
prefix = short ? "#{short}:|" : ""
|
|
22
|
-
"#{prefix}#{name}:"
|
|
23
|
-
end
|
|
24
15
|
|
|
25
16
|
def default? = @__default_p__ ||= default != None
|
|
26
17
|
|
|
18
|
+
def description_name = _all_names(:kwd)
|
|
19
|
+
|
|
27
20
|
def full_description(indent: 3, colors: :cyan, important: :bold, default_colors: :dim)
|
|
28
21
|
[
|
|
29
22
|
[
|
|
@@ -34,9 +27,7 @@ module L43
|
|
|
34
27
|
end
|
|
35
28
|
|
|
36
29
|
def name_description(colors: :cyan)
|
|
37
|
-
|
|
38
|
-
formatted_name = "#{short}:|#{formatted_name}" if short
|
|
39
|
-
[*Array(colors), formatted_name, :bold, :blue, "<value> ", :reset]
|
|
30
|
+
[*Array(colors), _all_names(:kwd) + " ", :bold, :blue, "<value> ", :reset]
|
|
40
31
|
end
|
|
41
32
|
|
|
42
33
|
def required? = default == None
|
data/lib/l43/xargs/parse.rb
CHANGED
data/lib/l43/xargs/version.rb
CHANGED
data/lib/l43/xargs.rb
CHANGED
|
@@ -33,6 +33,7 @@ module L43
|
|
|
33
33
|
|
|
34
34
|
attr_reader :argv, :autohelp, :defined_args, :last_added, :program_name, :usage
|
|
35
35
|
|
|
36
|
+
# extend Core::Forwarder
|
|
36
37
|
def add_desc(*desc, indent: nil, name: nil)
|
|
37
38
|
if name
|
|
38
39
|
element = defined_args.get_element(name) do
|
|
@@ -55,6 +56,20 @@ module L43
|
|
|
55
56
|
self
|
|
56
57
|
end
|
|
57
58
|
|
|
59
|
+
def def_alias(name, for_kwd: nil, for_flag: nil)
|
|
60
|
+
case [for_kwd, for_flag]
|
|
61
|
+
in nil, nil
|
|
62
|
+
raise ArgumentError, "exactly one of the two keyword arguments for_kwd:, for_flag: has to be set, none was"
|
|
63
|
+
in nil, _
|
|
64
|
+
defined_args.def_flag_alias(name, for_flag)
|
|
65
|
+
in _, nil
|
|
66
|
+
defined_args.def_kwd_alias(name, for_kwd)
|
|
67
|
+
else
|
|
68
|
+
raise ArgumentError, "exactly one of the two keyword arguments for_kwd:, for_flag: has to be set, both were"
|
|
69
|
+
end
|
|
70
|
+
self
|
|
71
|
+
end
|
|
72
|
+
|
|
58
73
|
def def_check(name=nil, desc:, &blk)
|
|
59
74
|
checks << Check.new(name:, desc:, &blk)
|
|
60
75
|
self
|
|
@@ -72,8 +87,8 @@ module L43
|
|
|
72
87
|
|
|
73
88
|
def errors = result.errors
|
|
74
89
|
|
|
75
|
-
def help_description(indent: 1, newline: true, sections: true, section_colors: [:bold, :green])
|
|
76
|
-
defined_args.help_description(indent:, newline:, program_name:, sections:, section_colors:, usage:)
|
|
90
|
+
def help_description(lines=[], indent: 1, newline: true, sections: true, section_colors: [:bold, :green])
|
|
91
|
+
defined_args.help_description(lines, indent:, newline:, program_name:, sections:, section_colors:, usage:)
|
|
77
92
|
end
|
|
78
93
|
|
|
79
94
|
def forward_to_kwds!(subject, *args, private: true, without: [])
|
|
@@ -106,8 +121,8 @@ module L43
|
|
|
106
121
|
end
|
|
107
122
|
end
|
|
108
123
|
|
|
109
|
-
def print_help(indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false, device: $stderr)
|
|
110
|
-
defined_args.print_help(indent:, newline:, program_name:, sections:, section_colors:, usage:, device:)
|
|
124
|
+
def print_help(lines=[], indent: 1, newline: true, program_name: nil, sections: true, section_colors: [:bold, :green], usage: false, device: $stderr)
|
|
125
|
+
defined_args.print_help(lines, indent:, newline:, program_name:, sections:, section_colors:, usage:, device:)
|
|
111
126
|
end
|
|
112
127
|
|
|
113
128
|
def result
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: l43_xargs
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.1.
|
|
4
|
+
version: 0.1.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Robert Dober
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date: 2026-09-
|
|
10
|
+
date: 2026-09-05 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: ostruct
|
|
@@ -67,6 +67,7 @@ files:
|
|
|
67
67
|
- lib/l43/xargs/deconstruct.rb
|
|
68
68
|
- lib/l43/xargs/defined_args.rb
|
|
69
69
|
- lib/l43/xargs/descriptions.rb
|
|
70
|
+
- lib/l43/xargs/elements/common.rb
|
|
70
71
|
- lib/l43/xargs/flag.rb
|
|
71
72
|
- lib/l43/xargs/forwarder.rb
|
|
72
73
|
- lib/l43/xargs/keyword.rb
|