mcli 0.7.0 → 0.8.0
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/README.md +65 -1
- data/lib/mcli.rb +1 -6
- data/lib/mcli/command.rb +9 -5
- data/lib/mcli/command_group.rb +9 -0
- data/lib/mcli/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: 0011cb49282f8d026747d15ceaff822cedafb0e56920a0dcc952d35bc3d44c5e
|
4
|
+
data.tar.gz: 744d35d6c593b620a5fd8aa996abb789af17411116560b136a3c824aba37cd84
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1acacb7282ef455e98d85caaa33e1396c79fb388962fc247df65d371b5efcf3ac7e74d061e146ae021ae9243970b54acb19053f4f600ffd0078df474b73e2446
|
7
|
+
data.tar.gz: 3c74baee24bcf1d03761877cd1b3b2e2d88357220f273cfc682631f8a2a6e326975ed5df5f194bc303481cbba94c29a8f8294287eee04d326997b5086c4da4d4
|
data/README.md
CHANGED
@@ -200,7 +200,7 @@ Heads: false
|
|
200
200
|
#!/usr/bin/env ruby
|
201
201
|
require 'mcli'
|
202
202
|
|
203
|
-
class
|
203
|
+
class Capture < MCLI::Command
|
204
204
|
register_as :capture
|
205
205
|
capture_all!
|
206
206
|
|
@@ -217,6 +217,70 @@ $ ./capture.rb capture --toast=cool one two -a ok three
|
|
217
217
|
["--toast=cool", "one", "two", "-a", "ok", "three"]
|
218
218
|
```
|
219
219
|
|
220
|
+
##### Register a command as the root command
|
221
|
+
```ruby
|
222
|
+
#root.rb
|
223
|
+
```
|
224
|
+
```ruby
|
225
|
+
#!/usr/bin/env ruby
|
226
|
+
require 'mcli'
|
227
|
+
|
228
|
+
class Root < MCLI::Command
|
229
|
+
register_as_root
|
230
|
+
option 'option'
|
231
|
+
|
232
|
+
def run
|
233
|
+
puts "#{arg.inspect}"
|
234
|
+
puts "#{options[:root]}"
|
235
|
+
end
|
236
|
+
end
|
237
|
+
|
238
|
+
MCLI.run
|
239
|
+
```
|
240
|
+
|
241
|
+
```bash
|
242
|
+
$ ./root.rb arg --option opt
|
243
|
+
[arg]
|
244
|
+
opt
|
245
|
+
```
|
246
|
+
|
247
|
+
##### Register nested commands
|
248
|
+
```ruby
|
249
|
+
#nestable.rb
|
250
|
+
```
|
251
|
+
```ruby
|
252
|
+
#!/usr/bin/env ruby
|
253
|
+
require 'mcli'
|
254
|
+
|
255
|
+
class Nestable < MCLI::Command
|
256
|
+
register_as :nestable
|
257
|
+
capture_all!
|
258
|
+
|
259
|
+
def run
|
260
|
+
NestedGroup.call(args)
|
261
|
+
end
|
262
|
+
|
263
|
+
class NestedGroup < MCLI::CommandGroup
|
264
|
+
end
|
265
|
+
end
|
266
|
+
|
267
|
+
class NestedCommand < MCLI::Command
|
268
|
+
register_as :command, to: Nestable::Group
|
269
|
+
capture_all!
|
270
|
+
|
271
|
+
def run
|
272
|
+
puts args.inspect
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
276
|
+
MCLI.run
|
277
|
+
```
|
278
|
+
|
279
|
+
```bash
|
280
|
+
$ ./nestable.rb nestable command --toast=cool one two -a ok three
|
281
|
+
["--toast=cool", "one", "two", "-a", "ok", "three"]
|
282
|
+
```
|
283
|
+
|
220
284
|
## Development
|
221
285
|
|
222
286
|
After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
|
data/lib/mcli.rb
CHANGED
@@ -9,12 +9,7 @@ require 'mcli/null_command'
|
|
9
9
|
module MCLI
|
10
10
|
class << self
|
11
11
|
def run
|
12
|
-
|
13
|
-
|
14
|
-
CommandGroup.commands.fetch(command.to_s.to_sym) do |command|
|
15
|
-
ARGV.unshift(command)
|
16
|
-
CommandGroup.root_command || NullCommand
|
17
|
-
end.call
|
12
|
+
CommandGroup.call(ARGV.dup)
|
18
13
|
end
|
19
14
|
end
|
20
15
|
end
|
data/lib/mcli/command.rb
CHANGED
@@ -16,7 +16,7 @@ class MCLI::Command
|
|
16
16
|
end
|
17
17
|
end
|
18
18
|
|
19
|
-
parser.parse!
|
19
|
+
parser.parse!(@args)
|
20
20
|
|
21
21
|
self.class.options
|
22
22
|
.select { |option| option.required == true }
|
@@ -59,9 +59,9 @@ class MCLI::Command
|
|
59
59
|
@options ||= []
|
60
60
|
end
|
61
61
|
|
62
|
-
def register_as(command_name)
|
62
|
+
def register_as(command_name, to: default_command_group)
|
63
63
|
@command_name = command_name
|
64
|
-
|
64
|
+
to.register(command_name, self)
|
65
65
|
end
|
66
66
|
|
67
67
|
def register_as_root
|
@@ -80,8 +80,12 @@ class MCLI::Command
|
|
80
80
|
@command_name
|
81
81
|
end
|
82
82
|
|
83
|
-
def
|
84
|
-
|
83
|
+
def default_command_group
|
84
|
+
MCLI::CommandGroup
|
85
|
+
end
|
86
|
+
|
87
|
+
def call(args)
|
88
|
+
new(args).tap do |command|
|
85
89
|
begin
|
86
90
|
command.parse unless capture_all?
|
87
91
|
command.run
|
data/lib/mcli/command_group.rb
CHANGED
@@ -19,6 +19,15 @@ class MCLI::CommandGroup
|
|
19
19
|
def root_command
|
20
20
|
@root_command
|
21
21
|
end
|
22
|
+
|
23
|
+
def call(args)
|
24
|
+
command = args.shift
|
25
|
+
|
26
|
+
commands.fetch(command.to_s.to_sym) do |command|
|
27
|
+
args.unshift(command)
|
28
|
+
root_command || MCLI::NullCommand
|
29
|
+
end.call(args)
|
30
|
+
end
|
22
31
|
end
|
23
32
|
end
|
24
33
|
|
data/lib/mcli/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mcli
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.8.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- John Thomas
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-01-
|
11
|
+
date: 2021-01-17 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|