lino 2.2.0.pre.5 → 2.2.0.pre.6
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/Gemfile.lock +1 -1
- data/README.md +266 -35
- data/lib/lino/command_line_builder.rb +11 -0
- data/lib/lino/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 9aefe3408616b3ae2841a469c5968f05a3d93f069b481ab3a311b37c5c99a19c
|
4
|
+
data.tar.gz: 36aab763064d14623437733908fdf4dcc1662431aa74ef5b296d8966799e6713
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a0492eb20f00aa07778fe583f1ae8e59516b2ca15a745a5c1f754401db2c6ab5c16f6ee5804b0517c434180a4dab376d499c6d881e7dac1db9a6433e2e6b8aa1
|
7
|
+
data.tar.gz: d3d77fe67e292480d87d323887ecd93292149ab7cb3a510b32c9accd721d3c465b8a12cfa7b84c8ad9b2a8310c5702efc39fb91c19a787a1a1d2e299061701be
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -41,10 +41,13 @@ command_line.execute
|
|
41
41
|
### `Lino::CommandLineBuilder`
|
42
42
|
|
43
43
|
The `CommandLineBuilder` allows a number of different styles of commands to be
|
44
|
-
built
|
44
|
+
built.
|
45
|
+
|
46
|
+
#### Flags
|
47
|
+
|
48
|
+
Flags can be added with `#with_flag`:
|
45
49
|
|
46
50
|
```ruby
|
47
|
-
# commands with flags
|
48
51
|
Lino::CommandLineBuilder.for_command('ls')
|
49
52
|
.with_flag('-l')
|
50
53
|
.with_flag('-a')
|
@@ -52,8 +55,24 @@ Lino::CommandLineBuilder.for_command('ls')
|
|
52
55
|
.to_s
|
53
56
|
|
54
57
|
# => ls -l -a
|
58
|
+
```
|
55
59
|
|
56
|
-
|
60
|
+
or `#with_flags`:
|
61
|
+
|
62
|
+
```ruby
|
63
|
+
Lino::CommandLineBuilder.for_command('ls')
|
64
|
+
.with_flags(%w[-l -a])
|
65
|
+
.build
|
66
|
+
.to_s
|
67
|
+
|
68
|
+
# => ls -l -a
|
69
|
+
```
|
70
|
+
|
71
|
+
#### Options
|
72
|
+
|
73
|
+
Options with values can be added with `#with_option`:
|
74
|
+
|
75
|
+
```ruby
|
57
76
|
Lino::CommandLineBuilder.for_command('gpg')
|
58
77
|
.with_option('--recipient', 'tobyclemson@gmail.com')
|
59
78
|
.with_option('--sign', './doc.txt')
|
@@ -61,8 +80,11 @@ Lino::CommandLineBuilder.for_command('gpg')
|
|
61
80
|
.to_s
|
62
81
|
|
63
82
|
# => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
|
83
|
+
```
|
64
84
|
|
65
|
-
|
85
|
+
or `#with_options`, either as a hash:
|
86
|
+
|
87
|
+
```ruby
|
66
88
|
Lino::CommandLineBuilder.for_command('gpg')
|
67
89
|
.with_options({
|
68
90
|
'--recipient' => 'tobyclemson@gmail.com',
|
@@ -72,8 +94,11 @@ Lino::CommandLineBuilder.for_command('gpg')
|
|
72
94
|
.to_s
|
73
95
|
|
74
96
|
# => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
|
97
|
+
```
|
75
98
|
|
76
|
-
|
99
|
+
or as an array:
|
100
|
+
|
101
|
+
```ruby
|
77
102
|
Lino::CommandLineBuilder.for_command('gpg')
|
78
103
|
.with_options(
|
79
104
|
[
|
@@ -85,16 +110,27 @@ Lino::CommandLineBuilder.for_command('gpg')
|
|
85
110
|
.to_s
|
86
111
|
|
87
112
|
# => gpg --recipient tobyclemson@gmail.com --sign ./doc.txt
|
113
|
+
```
|
114
|
+
|
115
|
+
Some commands allow options to be repeated:
|
88
116
|
|
89
|
-
|
117
|
+
```ruby
|
90
118
|
Lino::CommandLineBuilder.for_command('example.sh')
|
91
119
|
.with_repeated_option('--opt', ['file1.txt', nil, '', 'file2.txt'])
|
92
120
|
.build
|
93
121
|
.to_s
|
94
122
|
|
95
123
|
# => example.sh --opt file1.txt --opt file2.txt
|
124
|
+
```
|
125
|
+
|
126
|
+
> Note: `lino` ignores `nil` or empty option values in the resulting command
|
127
|
+
> line.
|
96
128
|
|
97
|
-
|
129
|
+
#### Arguments
|
130
|
+
|
131
|
+
Arguments can be added using `#with_argument`:
|
132
|
+
|
133
|
+
```ruby
|
98
134
|
Lino::CommandLineBuilder.for_command('diff')
|
99
135
|
.with_argument('./file1.txt')
|
100
136
|
.with_argument('./file2.txt')
|
@@ -102,16 +138,28 @@ Lino::CommandLineBuilder.for_command('diff')
|
|
102
138
|
.to_s
|
103
139
|
|
104
140
|
# => diff ./file1.txt ./file2.txt
|
141
|
+
```
|
105
142
|
|
106
|
-
|
143
|
+
or `#with_arguments`, as an array:
|
144
|
+
|
145
|
+
```ruby
|
107
146
|
Lino::CommandLineBuilder.for_command('diff')
|
108
147
|
.with_arguments(['./file1.txt', nil, '', './file2.txt'])
|
109
148
|
.build
|
110
149
|
.to_s
|
111
150
|
|
112
151
|
# => diff ./file1.txt ./file2.txt
|
152
|
+
```
|
153
|
+
|
154
|
+
> Note: `lino` ignores `nil` or empty argument values in the resulting command
|
155
|
+
> line.
|
156
|
+
|
157
|
+
#### Option Separators
|
113
158
|
|
114
|
-
|
159
|
+
By default, `lino` separates option values from the option by a space. This
|
160
|
+
can be overridden globally using `#with_option_separator`:
|
161
|
+
|
162
|
+
```ruby
|
115
163
|
Lino::CommandLineBuilder.for_command('java')
|
116
164
|
.with_option_separator(':')
|
117
165
|
.with_option('-splash', './images/splash.jpg')
|
@@ -120,44 +168,132 @@ Lino::CommandLineBuilder.for_command('java')
|
|
120
168
|
.to_s
|
121
169
|
|
122
170
|
# => java -splash:./images/splash.jpg ./application.jar
|
171
|
+
```
|
172
|
+
|
173
|
+
The option separator can be overridden on an option by option basis:
|
123
174
|
|
124
|
-
|
175
|
+
```ruby
|
176
|
+
Lino::CommandLineBuilder.for_command('java')
|
177
|
+
.with_option('-splash', './images/splash.jpg', separator: ':')
|
178
|
+
.with_argument('./application.jar')
|
179
|
+
.build
|
180
|
+
.to_s
|
181
|
+
|
182
|
+
# => java -splash:./images/splash.jpg ./application.jar
|
183
|
+
```
|
184
|
+
|
185
|
+
> Note: `#with_options` supports separator overriding when the options are
|
186
|
+
> passed as an array of hashes and a `separator` key is included in the
|
187
|
+
> hash.
|
188
|
+
|
189
|
+
> Note: `#with_repeated_option` also supports the `separator` named parameter.
|
190
|
+
|
191
|
+
> Note: option specific separators take precedence over the global option
|
192
|
+
> separator
|
193
|
+
|
194
|
+
#### Option Quoting
|
195
|
+
|
196
|
+
By default, `lino` does not quote option values. This can be overridden
|
197
|
+
globally using `#with_option_quoting`:
|
198
|
+
|
199
|
+
```ruby
|
200
|
+
Lino::CommandLineBuilder.for_command('gpg')
|
201
|
+
.with_option_quoting('"')
|
202
|
+
.with_option('--sign', 'some file.txt')
|
203
|
+
.build
|
204
|
+
.to_s
|
205
|
+
|
206
|
+
# => gpg --sign "some file.txt"
|
207
|
+
```
|
208
|
+
|
209
|
+
The option quoting can be overridden on an option by option basis:
|
210
|
+
|
211
|
+
```ruby
|
212
|
+
Lino::CommandLineBuilder.for_command('java')
|
213
|
+
.with_option('-splash', './images/splash.jpg', quoting: '"')
|
214
|
+
.with_argument('./application.jar')
|
215
|
+
.build
|
216
|
+
.to_s
|
217
|
+
|
218
|
+
# => java -splash "./images/splash.jpg" ./application.jar
|
219
|
+
```
|
220
|
+
|
221
|
+
> Note: `#with_options` supports quoting overriding when the options are
|
222
|
+
> passed as an array of hashes and a `quoting` key is included in the
|
223
|
+
> hash.
|
224
|
+
|
225
|
+
> Note: `#with_repeated_option` also supports the `quoting` named parameter.
|
226
|
+
|
227
|
+
> Note: option specific quoting take precedence over the global option
|
228
|
+
> quoting
|
229
|
+
|
230
|
+
#### Subcommands
|
231
|
+
|
232
|
+
Subcommands can be added using `#with_subcommand`:
|
233
|
+
|
234
|
+
```ruby
|
125
235
|
Lino::CommandLineBuilder.for_command('git')
|
126
236
|
.with_flag('--no-pager')
|
127
|
-
.with_subcommand('log')
|
128
|
-
sub.with_option('--since', '2016-01-01')
|
129
|
-
end
|
237
|
+
.with_subcommand('log')
|
130
238
|
.build
|
131
239
|
.to_s
|
132
240
|
|
133
|
-
# => git --no-pager log
|
241
|
+
# => git --no-pager log
|
242
|
+
```
|
134
243
|
|
135
|
-
|
244
|
+
Multi-level subcommands can be added using multiple `#with_subcommand`
|
245
|
+
invocations:
|
246
|
+
|
247
|
+
```ruby
|
136
248
|
Lino::CommandLineBuilder.for_command('gcloud')
|
137
249
|
.with_subcommand('sql')
|
138
250
|
.with_subcommand('instances')
|
139
251
|
.with_subcommand('set-root-password')
|
140
|
-
.with_subcommand('some-database')
|
141
|
-
sub.with_option('--password', 'super-secure')
|
142
|
-
end
|
252
|
+
.with_subcommand('some-database')
|
143
253
|
.build
|
144
254
|
.to_s
|
145
|
-
|
146
|
-
# => gcloud sql instances set-root-password some-database --password super-secure
|
147
255
|
|
148
|
-
#
|
256
|
+
# => gcloud sql instances set-root-password some-database
|
257
|
+
```
|
258
|
+
|
259
|
+
or using `#with_subcommands`:
|
260
|
+
|
261
|
+
```ruby
|
149
262
|
Lino::CommandLineBuilder.for_command('gcloud')
|
150
263
|
.with_subcommands(
|
151
264
|
%w[sql instances set-root-password some-database]
|
152
|
-
)
|
153
|
-
sub.with_option('--password', 'super-secure')
|
154
|
-
end
|
265
|
+
)
|
155
266
|
.build
|
156
267
|
.to_s
|
157
268
|
|
158
|
-
# => gcloud sql instances set-root-password some-database
|
269
|
+
# => gcloud sql instances set-root-password some-database
|
270
|
+
```
|
271
|
+
|
272
|
+
Subcommands also support options via `#with_flag`, `#with_flags`,
|
273
|
+
`#with_option`, `#with_options` and `#with_repeated_option` just like commands,
|
274
|
+
via a block, for example:
|
275
|
+
|
276
|
+
```ruby
|
277
|
+
Lino::CommandLineBuilder.for_command('git')
|
278
|
+
.with_flag('--no-pager')
|
279
|
+
.with_subcommand('log') do |sub|
|
280
|
+
sub.with_option('--since', '2016-01-01')
|
281
|
+
end
|
282
|
+
.build
|
283
|
+
.to_s
|
284
|
+
|
285
|
+
# => git --no-pager log --since 2016-01-01
|
286
|
+
```
|
287
|
+
|
288
|
+
> Note: `#with_subcommands` also supports a block, which applies in the context
|
289
|
+
> of the last subcommand in the passed array.
|
290
|
+
|
291
|
+
#### Environment Variables
|
292
|
+
|
293
|
+
Command lines can be prefixed with environment variables using
|
294
|
+
`#with_environment_variable`:
|
159
295
|
|
160
|
-
|
296
|
+
```ruby
|
161
297
|
Lino::CommandLineBuilder.for_command('node')
|
162
298
|
.with_environment_variable('PORT', '3030')
|
163
299
|
.with_environment_variable('LOG_LEVEL', 'debug')
|
@@ -166,31 +302,73 @@ Lino::CommandLineBuilder.for_command('node')
|
|
166
302
|
.to_s
|
167
303
|
|
168
304
|
# => PORT=3030 LOG_LEVEL=debug node ./server.js
|
305
|
+
```
|
306
|
+
|
307
|
+
or `#with_environment_variables`, either as a hash:
|
308
|
+
|
309
|
+
```ruby
|
310
|
+
Lino::CommandLineBuilder.for_command('node')
|
311
|
+
.with_environment_variables({
|
312
|
+
'PORT' => '3030',
|
313
|
+
'LOG_LEVEL' => 'debug'
|
314
|
+
})
|
315
|
+
.build
|
316
|
+
.to_s
|
317
|
+
|
318
|
+
# => PORT=3030 LOG_LEVEL=debug node ./server.js
|
319
|
+
```
|
169
320
|
|
170
|
-
|
171
|
-
# and arguments
|
321
|
+
or as an array:
|
172
322
|
|
173
|
-
|
323
|
+
```ruby
|
324
|
+
Lino::CommandLineBuilder.for_command('node')
|
325
|
+
.with_environment_variables(
|
326
|
+
[
|
327
|
+
{ name: 'PORT', value: '3030' },
|
328
|
+
{ name: 'LOG_LEVEL', value: 'debug' }
|
329
|
+
]
|
330
|
+
)
|
331
|
+
.build
|
332
|
+
.to_s
|
333
|
+
|
334
|
+
# => PORT=3030 LOG_LEVEL=debug node ./server.js
|
335
|
+
```
|
336
|
+
|
337
|
+
#### Option Placement
|
338
|
+
|
339
|
+
By default, `lino` places top-level options after the command, before all
|
340
|
+
subcommands and arguments.
|
341
|
+
|
342
|
+
This is equivalent to calling `#with_options_after_command`:
|
343
|
+
|
344
|
+
```ruby
|
174
345
|
Lino::CommandLineBuilder.for_command('gcloud')
|
175
346
|
.with_options_after_command
|
176
347
|
.with_option('--password', 'super-secure')
|
177
|
-
.with_subcommands(%w[sql instances set-root-password
|
348
|
+
.with_subcommands(%w[sql instances set-root-password])
|
178
349
|
.build
|
179
350
|
.to_s
|
180
351
|
|
181
|
-
# => gcloud --password super-secure sql instances set-root-password
|
352
|
+
# => gcloud --password super-secure sql instances set-root-password
|
353
|
+
```
|
354
|
+
|
355
|
+
Alternatively, top-level options can be placed after all subcommands using
|
356
|
+
`#with_options_after_subcommands`:
|
182
357
|
|
183
|
-
|
358
|
+
```ruby
|
184
359
|
Lino::CommandLineBuilder.for_command('gcloud')
|
185
360
|
.with_options_after_subcommands
|
186
361
|
.with_option('--password', 'super-secure')
|
187
|
-
.with_subcommands(%w[sql instances set-root-password
|
362
|
+
.with_subcommands(%w[sql instances set-root-password])
|
188
363
|
.build
|
189
364
|
.to_s
|
190
365
|
|
191
|
-
# => gcloud sql instances set-root-password
|
366
|
+
# => gcloud sql instances set-root-password --password super-secure
|
367
|
+
```
|
368
|
+
|
369
|
+
or, after all arguments, using `#with_options_after_arguments`:
|
192
370
|
|
193
|
-
|
371
|
+
```ruby
|
194
372
|
Lino::CommandLineBuilder.for_command('ls')
|
195
373
|
.with_options_after_arguments
|
196
374
|
.with_flag('-l')
|
@@ -201,6 +379,59 @@ Lino::CommandLineBuilder.for_command('ls')
|
|
201
379
|
# => ls /some/directory -l
|
202
380
|
```
|
203
381
|
|
382
|
+
#### Appliables
|
383
|
+
|
384
|
+
Command and subcommand builders both support passing 'appliables' that are
|
385
|
+
applied to the builder allowing an operation to be encapsulated in an object.
|
386
|
+
|
387
|
+
Given an appliable type:
|
388
|
+
|
389
|
+
```ruby
|
390
|
+
class AppliableOption
|
391
|
+
def initialize(option, value)
|
392
|
+
@option = option
|
393
|
+
@value = value
|
394
|
+
end
|
395
|
+
|
396
|
+
def apply(builder)
|
397
|
+
builder.with_option(@option, @value)
|
398
|
+
end
|
399
|
+
end
|
400
|
+
```
|
401
|
+
|
402
|
+
an instance of the appliable can be applied using `#with_appliable`:
|
403
|
+
|
404
|
+
```ruby
|
405
|
+
Lino::CommandLineBuilder.for_command('gpg')
|
406
|
+
.with_appliable(AppliableOption.new('--recipient', 'tobyclemson@gmail.com'))
|
407
|
+
.with_flag('--sign')
|
408
|
+
.with_argument('/some/file.txt')
|
409
|
+
.build
|
410
|
+
.to_s
|
411
|
+
|
412
|
+
# => gpg --recipient tobyclemson@gmail.com --sign /some/file.txt
|
413
|
+
```
|
414
|
+
|
415
|
+
or multiple with `#with_appliables`:
|
416
|
+
|
417
|
+
```ruby
|
418
|
+
Lino::CommandLineBuilder.for_command('gpg')
|
419
|
+
.with_appliables([
|
420
|
+
AppliableOption.new('--recipient', 'user@example.com'),
|
421
|
+
AppliableOption.new('--output', '/signed.txt')
|
422
|
+
])
|
423
|
+
.with_flag('--sign')
|
424
|
+
.with_argument('/file.txt')
|
425
|
+
.build
|
426
|
+
.to_s
|
427
|
+
|
428
|
+
# => gpg --recipient user@example.com --output /signed.txt --sign /file.txt
|
429
|
+
```
|
430
|
+
|
431
|
+
> Note: an 'appliable' is any object that has an `#apply` method.
|
432
|
+
|
433
|
+
> Note: `lino` ignores `nil` or empty appliables in the resulting command line.
|
434
|
+
|
204
435
|
### `Lino::CommandLine`
|
205
436
|
|
206
437
|
A `CommandLine` can be executed using the `#execute` method:
|
@@ -113,6 +113,17 @@ module Lino
|
|
113
113
|
)
|
114
114
|
end
|
115
115
|
|
116
|
+
def with_environment_variables(environment_variables)
|
117
|
+
return self if missing?(environment_variables)
|
118
|
+
|
119
|
+
environment_variables.entries.inject(self) do |s, var|
|
120
|
+
s.with_environment_variable(
|
121
|
+
var.include?(:name) ? var[:name] : var[0],
|
122
|
+
var.include?(:value) ? var[:value] : var[1]
|
123
|
+
)
|
124
|
+
end
|
125
|
+
end
|
126
|
+
|
116
127
|
def build
|
117
128
|
components = formatted_components
|
118
129
|
command_line = SELECTORS[@option_placement]
|
data/lib/lino/version.rb
CHANGED