lino 2.3.0 → 2.6.0.pre.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/README.md +27 -0
- data/lib/lino/command_line_builder.rb +50 -18
- data/lib/lino/options.rb +28 -8
- data/lib/lino/utilities.rb +8 -0
- data/lib/lino/version.rb +1 -1
- metadata +4 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c4c737157f6552423f6fbb2a5b4263e4f2a76b543d6f7ea15408988caeca61ff
|
4
|
+
data.tar.gz: 20257769cf4a2807dc6a826e1e22ca5b52ecb1c650f8ed69662f787c013c2b64
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 58d4387c603f527dec478c0ee57ded0af915da0111042ea8a16d10d54050755322ee1f6849fd3b427b783feb4116f6c75fe2ab56c38bcef21d782ed650b99db5
|
7
|
+
data.tar.gz: 11d9561cb8c69833c035da08e04c5afb78ac54a90db6c1c2b1c59c752ebb199b0eb89d613d7ecdb60bb7c70b9d8afcffee3b7b3bfa7d024c3806da58dd89ac71
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -379,6 +379,33 @@ Lino::CommandLineBuilder.for_command('ls')
|
|
379
379
|
# => ls /some/directory -l
|
380
380
|
```
|
381
381
|
|
382
|
+
The option placement can be overridden on an option by option basis:
|
383
|
+
|
384
|
+
```ruby
|
385
|
+
Lino::CommandLineBuilder.for_command('gcloud')
|
386
|
+
.with_options_after_subcommands
|
387
|
+
.with_option('--log-level', 'debug', placement: :after_command)
|
388
|
+
.with_option('--password', 'super-secure')
|
389
|
+
.with_subcommands(%w[sql instances set-root-password])
|
390
|
+
.build
|
391
|
+
.to_s
|
392
|
+
|
393
|
+
# => gcloud --log-level debug sql instances set-root-password \
|
394
|
+
# --password super-secure
|
395
|
+
```
|
396
|
+
|
397
|
+
The `:placement` keyword argument accepts placement values of `:after_command`,
|
398
|
+
`:after_subcommands` and `:after_arguments`.
|
399
|
+
|
400
|
+
> Note: `#with_options` supports placement overriding when the options are
|
401
|
+
> passed as an array of hashes and a `placement` key is included in the
|
402
|
+
> hash.
|
403
|
+
|
404
|
+
> Note: `#with_repeated_option` also supports the `placement` named parameter.
|
405
|
+
|
406
|
+
> Note: option specific placement take precedence over the global option
|
407
|
+
> placement
|
408
|
+
|
382
409
|
#### Appliables
|
383
410
|
|
384
411
|
Command and subcommand builders both support passing 'appliables' that are
|
@@ -10,15 +10,6 @@ require_relative 'appliables'
|
|
10
10
|
module Lino
|
11
11
|
# rubocop:disable Metrics/ClassLength
|
12
12
|
class CommandLineBuilder
|
13
|
-
SELECTORS = {
|
14
|
-
after_command:
|
15
|
-
%i[environment_variables command options subcommands arguments],
|
16
|
-
after_subcommands:
|
17
|
-
%i[environment_variables command subcommands options arguments],
|
18
|
-
after_arguments:
|
19
|
-
%i[environment_variables command subcommands arguments options]
|
20
|
-
}.freeze
|
21
|
-
|
22
13
|
include Lino::Utilities
|
23
14
|
include Lino::Options
|
24
15
|
include Lino::Appliables
|
@@ -49,9 +40,12 @@ module Lino
|
|
49
40
|
@option_quoting = option_quoting
|
50
41
|
@option_placement = option_placement
|
51
42
|
end
|
43
|
+
|
52
44
|
# rubocop:enable Metrics/ParameterLists
|
53
45
|
|
54
46
|
def with_subcommand(subcommand, &block)
|
47
|
+
return self if missing?(subcommand)
|
48
|
+
|
55
49
|
with(
|
56
50
|
subcommands: @subcommands.add(
|
57
51
|
(block || ->(sub) { sub }).call(
|
@@ -62,6 +56,8 @@ module Lino
|
|
62
56
|
end
|
63
57
|
|
64
58
|
def with_subcommands(subcommands, &block)
|
59
|
+
return self if missing?(subcommands)
|
60
|
+
|
65
61
|
without_block = subcommands[0...-1]
|
66
62
|
with_block = subcommands.last
|
67
63
|
|
@@ -78,16 +74,20 @@ module Lino
|
|
78
74
|
with(option_quoting: character)
|
79
75
|
end
|
80
76
|
|
77
|
+
def with_option_placement(option_placement)
|
78
|
+
with(option_placement: option_placement)
|
79
|
+
end
|
80
|
+
|
81
81
|
def with_options_after_command
|
82
|
-
|
82
|
+
with_option_placement(:after_command)
|
83
83
|
end
|
84
84
|
|
85
85
|
def with_options_after_subcommands
|
86
|
-
|
86
|
+
with_option_placement(:after_subcommands)
|
87
87
|
end
|
88
88
|
|
89
89
|
def with_options_after_arguments
|
90
|
-
|
90
|
+
with_option_placement(:after_arguments)
|
91
91
|
end
|
92
92
|
|
93
93
|
def with_argument(argument)
|
@@ -126,16 +126,29 @@ module Lino
|
|
126
126
|
|
127
127
|
def build
|
128
128
|
components = formatted_components
|
129
|
-
command_line =
|
130
|
-
|
131
|
-
|
132
|
-
|
129
|
+
command_line =
|
130
|
+
component_paths
|
131
|
+
.collect { |path| path.inject(components) { |c, p| c && c[p] } }
|
132
|
+
.reject(&:empty?)
|
133
|
+
.join(' ')
|
133
134
|
|
134
135
|
CommandLine.new(command_line)
|
135
136
|
end
|
136
137
|
|
137
138
|
private
|
138
139
|
|
140
|
+
def component_paths
|
141
|
+
[
|
142
|
+
%i[environment_variables],
|
143
|
+
%i[command],
|
144
|
+
%i[options after_command],
|
145
|
+
%i[subcommands],
|
146
|
+
%i[options after_subcommands],
|
147
|
+
%i[arguments],
|
148
|
+
%i[options after_arguments]
|
149
|
+
]
|
150
|
+
end
|
151
|
+
|
139
152
|
def formatted_components
|
140
153
|
{
|
141
154
|
environment_variables: formatted_environment_variables,
|
@@ -152,13 +165,24 @@ module Lino
|
|
152
165
|
end
|
153
166
|
end
|
154
167
|
|
155
|
-
def
|
168
|
+
def formatted_options_with_placement(placement)
|
156
169
|
map_and_join(
|
157
|
-
|
170
|
+
options_with_placement(placement),
|
158
171
|
&(quote_with(@option_quoting) >> join_with(@option_separator))
|
159
172
|
)
|
160
173
|
end
|
161
174
|
|
175
|
+
def formatted_options
|
176
|
+
%i[
|
177
|
+
after_command
|
178
|
+
after_subcommands
|
179
|
+
after_arguments
|
180
|
+
].inject({}) do |options, placement|
|
181
|
+
options
|
182
|
+
.merge({ placement => formatted_options_with_placement(placement) })
|
183
|
+
end
|
184
|
+
end
|
185
|
+
|
162
186
|
def formatted_subcommands
|
163
187
|
map_and_join(@subcommands) do |sub|
|
164
188
|
sub.build(@option_separator, @option_quoting)
|
@@ -172,6 +196,13 @@ module Lino
|
|
172
196
|
)
|
173
197
|
end
|
174
198
|
|
199
|
+
def options_with_placement(placement)
|
200
|
+
@options.select { |o| o[:placement] == placement } +
|
201
|
+
if @option_placement == placement
|
202
|
+
@options.select { |o| o[:placement].nil? }
|
203
|
+
end
|
204
|
+
end
|
205
|
+
|
175
206
|
def with(**replacements)
|
176
207
|
CommandLineBuilder.new(**state.merge(replacements))
|
177
208
|
end
|
@@ -189,5 +220,6 @@ module Lino
|
|
189
220
|
}
|
190
221
|
end
|
191
222
|
end
|
223
|
+
|
192
224
|
# rubocop:enable Metrics/ClassLength
|
193
225
|
end
|
data/lib/lino/options.rb
CHANGED
@@ -6,14 +6,21 @@ module Lino
|
|
6
6
|
module Options
|
7
7
|
include Lino::Utilities
|
8
8
|
|
9
|
-
def with_option(
|
9
|
+
def with_option(
|
10
|
+
option,
|
11
|
+
value,
|
12
|
+
separator: nil,
|
13
|
+
quoting: nil,
|
14
|
+
placement: nil
|
15
|
+
)
|
10
16
|
return self if missing?(value)
|
11
17
|
|
12
18
|
with(options: @options.add(
|
13
19
|
{
|
14
20
|
components: [option, value],
|
15
21
|
separator: separator,
|
16
|
-
quoting: quoting
|
22
|
+
quoting: quoting,
|
23
|
+
placement: placement
|
17
24
|
}
|
18
25
|
))
|
19
26
|
end
|
@@ -23,17 +30,30 @@ module Lino
|
|
23
30
|
|
24
31
|
options.entries.inject(self) do |s, entry|
|
25
32
|
s.with_option(
|
26
|
-
entry
|
27
|
-
entry
|
28
|
-
separator: (entry
|
29
|
-
quoting: (entry
|
33
|
+
or_nth(entry, :option, 0),
|
34
|
+
or_nth(entry, :value, 1),
|
35
|
+
separator: or_nil(entry, :separator),
|
36
|
+
quoting: or_nil(entry, :quoting),
|
37
|
+
placement: or_nil(entry, :placement)
|
30
38
|
)
|
31
39
|
end
|
32
40
|
end
|
33
41
|
|
34
|
-
def with_repeated_option(
|
42
|
+
def with_repeated_option(
|
43
|
+
option,
|
44
|
+
values,
|
45
|
+
separator: nil,
|
46
|
+
quoting: nil,
|
47
|
+
placement: nil
|
48
|
+
)
|
35
49
|
values.inject(self) do |s, value|
|
36
|
-
s.with_option(
|
50
|
+
s.with_option(
|
51
|
+
option,
|
52
|
+
value,
|
53
|
+
separator: separator,
|
54
|
+
quoting: quoting,
|
55
|
+
placement: placement
|
56
|
+
)
|
37
57
|
end
|
38
58
|
end
|
39
59
|
|
data/lib/lino/utilities.rb
CHANGED
@@ -41,5 +41,13 @@ module Lino
|
|
41
41
|
components
|
42
42
|
end
|
43
43
|
end
|
44
|
+
|
45
|
+
def or_nil(enumerable, key)
|
46
|
+
enumerable.include?(key) ? enumerable[key] : nil
|
47
|
+
end
|
48
|
+
|
49
|
+
def or_nth(enumerable, key, index)
|
50
|
+
enumerable.include?(key) ? enumerable[key] : enumerable[index]
|
51
|
+
end
|
44
52
|
end
|
45
53
|
end
|
data/lib/lino/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: lino
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.
|
4
|
+
version: 2.6.0.pre.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Toby Clemson
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-05-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: hamster
|
@@ -244,9 +244,9 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
244
244
|
version: '2.6'
|
245
245
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
246
246
|
requirements:
|
247
|
-
- - "
|
247
|
+
- - ">"
|
248
248
|
- !ruby/object:Gem::Version
|
249
|
-
version:
|
249
|
+
version: 1.3.1
|
250
250
|
requirements: []
|
251
251
|
rubygems_version: 3.0.1
|
252
252
|
signing_key:
|