lino 2.6.0.pre.1 → 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 +1 -1
- data/README.md +27 -0
- data/lib/lino/command_line_builder.rb +46 -18
- data/lib/lino/options.rb +28 -8
- data/lib/lino/utilities.rb +8 -0
- data/lib/lino/version.rb +1 -1
- metadata +2 -2
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,6 +40,7 @@ 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)
|
@@ -82,16 +74,20 @@ module Lino
|
|
82
74
|
with(option_quoting: character)
|
83
75
|
end
|
84
76
|
|
77
|
+
def with_option_placement(option_placement)
|
78
|
+
with(option_placement: option_placement)
|
79
|
+
end
|
80
|
+
|
85
81
|
def with_options_after_command
|
86
|
-
|
82
|
+
with_option_placement(:after_command)
|
87
83
|
end
|
88
84
|
|
89
85
|
def with_options_after_subcommands
|
90
|
-
|
86
|
+
with_option_placement(:after_subcommands)
|
91
87
|
end
|
92
88
|
|
93
89
|
def with_options_after_arguments
|
94
|
-
|
90
|
+
with_option_placement(:after_arguments)
|
95
91
|
end
|
96
92
|
|
97
93
|
def with_argument(argument)
|
@@ -130,16 +126,29 @@ module Lino
|
|
130
126
|
|
131
127
|
def build
|
132
128
|
components = formatted_components
|
133
|
-
command_line =
|
134
|
-
|
135
|
-
|
136
|
-
|
129
|
+
command_line =
|
130
|
+
component_paths
|
131
|
+
.collect { |path| path.inject(components) { |c, p| c && c[p] } }
|
132
|
+
.reject(&:empty?)
|
133
|
+
.join(' ')
|
137
134
|
|
138
135
|
CommandLine.new(command_line)
|
139
136
|
end
|
140
137
|
|
141
138
|
private
|
142
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
|
+
|
143
152
|
def formatted_components
|
144
153
|
{
|
145
154
|
environment_variables: formatted_environment_variables,
|
@@ -156,13 +165,24 @@ module Lino
|
|
156
165
|
end
|
157
166
|
end
|
158
167
|
|
159
|
-
def
|
168
|
+
def formatted_options_with_placement(placement)
|
160
169
|
map_and_join(
|
161
|
-
|
170
|
+
options_with_placement(placement),
|
162
171
|
&(quote_with(@option_quoting) >> join_with(@option_separator))
|
163
172
|
)
|
164
173
|
end
|
165
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
|
+
|
166
186
|
def formatted_subcommands
|
167
187
|
map_and_join(@subcommands) do |sub|
|
168
188
|
sub.build(@option_separator, @option_quoting)
|
@@ -176,6 +196,13 @@ module Lino
|
|
176
196
|
)
|
177
197
|
end
|
178
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
|
+
|
179
206
|
def with(**replacements)
|
180
207
|
CommandLineBuilder.new(**state.merge(replacements))
|
181
208
|
end
|
@@ -193,5 +220,6 @@ module Lino
|
|
193
220
|
}
|
194
221
|
end
|
195
222
|
end
|
223
|
+
|
196
224
|
# rubocop:enable Metrics/ClassLength
|
197
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.6.0.pre.
|
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
|