cl 1.0.0 → 1.0.1
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 +5 -5
- data/CHANGELOG.md +1 -0
- data/Gemfile.lock +1 -1
- data/NOTES.md +4 -0
- data/README.md +131 -74
- data/examples/README.md +22 -0
- data/examples/{src → _src}/args/cast.erb.rb +0 -0
- data/examples/{src → _src}/args/opts.erb.rb +0 -0
- data/examples/{src → _src}/args/required.erb.rb +0 -0
- data/examples/{src → _src}/args/splat.erb.rb +0 -0
- data/examples/{src → _src}/gem.erb.rb +0 -0
- data/examples/{src → _src}/heroku.erb.rb +0 -0
- data/examples/{src → _src}/rakeish.erb.rb +0 -0
- data/examples/{src → _src}/readme/abstract.erb.rb +0 -0
- data/examples/{src → _src}/readme/alias.erb.rb +0 -0
- data/examples/{src → _src}/readme/arg.erb.rb +0 -0
- data/examples/{src → _src}/readme/arg_array.erb.rb +0 -0
- data/examples/{src → _src}/readme/arg_type.erb.rb +0 -0
- data/examples/{src → _src}/readme/args_splat.erb.rb +0 -0
- data/examples/{src → _src}/readme/array.erb.rb +0 -0
- data/examples/_src/readme/basic.erb.rb +70 -0
- data/examples/{src → _src}/readme/default.erb.rb +0 -0
- data/examples/{src → _src}/readme/deprecated.erb.rb +0 -0
- data/examples/{src → _src}/readme/deprecated_alias.erb.rb +0 -0
- data/examples/_src/readme/description.erb.rb +58 -0
- data/examples/{src → _src}/readme/downcase.erb.rb +0 -0
- data/examples/{src → _src}/readme/enum.erb.rb +0 -0
- data/examples/{src → _src}/readme/example.erb.rb +0 -0
- data/examples/{src → _src}/readme/format.erb.rb +0 -0
- data/examples/{src → _src}/readme/internal.erb.rb +0 -0
- data/examples/{src → _src}/readme/negate.erb.rb +0 -0
- data/examples/{src/readme/node.erb.rb → _src/readme/note.erb.rb} +0 -0
- data/examples/{src → _src}/readme/opts.erb.rb +0 -0
- data/examples/{src → _src}/readme/opts_block.erb.rb +0 -0
- data/examples/{src → _src}/readme/range.erb.rb +0 -0
- data/examples/_src/readme/registry.erb.rb +16 -0
- data/examples/{src → _src}/readme/required.erb.rb +0 -0
- data/examples/{src → _src}/readme/requireds.erb.rb +0 -0
- data/examples/{src → _src}/readme/requires.erb.rb +0 -0
- data/examples/_src/readme/runner.erb.rb +27 -0
- data/examples/_src/readme/runner_custom.erb.rb +25 -0
- data/examples/{src → _src}/readme/secret.erb.rb +0 -0
- data/examples/{src → _src}/readme/see.erb.rb +0 -0
- data/examples/{src → _src}/readme/type.erb.rb +0 -0
- data/examples/readme/basic +65 -0
- data/examples/readme/description +54 -0
- data/examples/readme/note +6 -4
- data/examples/readme/registry +13 -0
- data/examples/readme/runner +28 -0
- data/examples/readme/runner_custom +22 -0
- data/lib/cl/args.rb +10 -18
- data/lib/cl/cast.rb +46 -24
- data/lib/cl/help/cmd.rb +3 -55
- data/lib/cl/help/format.rb +69 -0
- data/lib/cl/help/table.rb +5 -2
- data/lib/cl/opt.rb +4 -0
- data/lib/cl/opts/validate.rb +117 -0
- data/lib/cl/opts.rb +11 -101
- data/lib/cl/version.rb +1 -1
- metadata +49 -36
- data/examples/readme/node +0 -19
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
|
-
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: d68ba1674ee398202a474abb83387fb296847aad
|
4
|
+
data.tar.gz: 3f410b5991158c25bc3ec7688fd9a86c56b7e11f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 26fac7251c6eead9ed449d3f5c1dfb61794eb1f6c7e008f069ac973afd912d84d93b75abaa84ca20f6f69d6642cc00694be28469b36ce8ce0a1f3d044ecb9c3d
|
7
|
+
data.tar.gz: 993d729a5b9fd4ae131d257601a93b57483ac6f6ba12e46409cffeda230e2a8573b1b9c22edc93392e6c7224de94f979962479fdb23d4b27df32796d84e2b685
|
data/CHANGELOG.md
CHANGED
@@ -19,6 +19,7 @@
|
|
19
19
|
* Add `opt '--one STR', format: /.+/`
|
20
20
|
* Add `opt '--one STR', enum: ['one', /\w+/]`
|
21
21
|
* Add `opt '--one STR', downcase: true`
|
22
|
+
* Add `opt '--one STR', upcase: true`
|
22
23
|
* Add `opt '--one STR', internal: true`, hide internal options from help output
|
23
24
|
* Add `opt '--one STR', example: 'foo'`
|
24
25
|
* Add `opt '--one STR', negate: %w(skip)`
|
data/Gemfile.lock
CHANGED
data/NOTES.md
CHANGED
@@ -13,3 +13,7 @@ x add yard docs
|
|
13
13
|
- refactor Help::Cmd and Table so that everything goes into one big table
|
14
14
|
- Ui classes really need to write error messages to stderr, not stdout
|
15
15
|
- make sure option aliases define accessors and predicates (see examples/readme/alias)
|
16
|
+
|
17
|
+
|
18
|
+
- validate and normalize type
|
19
|
+
- validate that there can only be one arg splat
|
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Cl [](https://travis-ci.
|
1
|
+
# Cl [](https://travis-ci.org/svenfuchs/cl) [](https://codeclimate.com/github/svenfuchs/cl) [](https://coveralls.io/github/svenfuchs/cl?branch=master) [](http://rubygems.org/gems/cl) [](http://rubydoc.info/github/svenfuchs/cl)
|
2
2
|
|
3
3
|
OptionParser based CLI support for rapid CLI development in an object-oriented
|
4
4
|
context.
|
@@ -12,6 +12,11 @@ after `gem --help`).
|
|
12
12
|
|
13
13
|
Further documentation is available on [rubydoc.info](https://www.rubydoc.info/github/svenfuchs/cl)
|
14
14
|
|
15
|
+
Examples in this README are included from [examples/readme](https://github.com/svenfuchs/cl/tree/master/examples/readme).
|
16
|
+
More examples can be found in [examples](https://github.com/svenfuchs/cl/tree/master/examples).
|
17
|
+
All examples are guaranteed to be up to date by the way of being [verified](https://github.com/svenfuchs/cl/blob/master/.travis.yml#L14)
|
18
|
+
on CI.
|
19
|
+
|
15
20
|
## Table of Contents
|
16
21
|
|
17
22
|
* [Basic Usage](#basic-usage)
|
@@ -46,7 +51,6 @@ Further documentation is available on [rubydoc.info](https://www.rubydoc.info/gi
|
|
46
51
|
## Basic Usage
|
47
52
|
|
48
53
|
```ruby
|
49
|
-
# lib/cli/owners/add.rb
|
50
54
|
module Owners
|
51
55
|
class Add < Cl::Cmd
|
52
56
|
summary 'Add one or more owners to an existing owner group'
|
@@ -58,48 +62,58 @@ module Owners
|
|
58
62
|
[...]
|
59
63
|
str
|
60
64
|
|
61
|
-
args :
|
65
|
+
args :owner
|
62
66
|
|
63
67
|
opt '-t', '--to TO', 'An existing owner group'
|
64
68
|
|
65
69
|
def run
|
66
|
-
#
|
67
|
-
# `to
|
70
|
+
# implement adding the owner as given in `owner` (as well as `args`)
|
71
|
+
# to the group given in `to` (as well as `opts[:to]`).
|
72
|
+
p owner: owner, to: to, to?: to?, args: args, opts: opts
|
68
73
|
end
|
69
74
|
end
|
70
75
|
end
|
71
76
|
|
72
|
-
# bin/owners
|
73
|
-
|
74
|
-
```
|
75
|
-
|
76
|
-
Running this, e.g. using `bin/owners add one,two --to group` will instantiate the
|
77
|
-
class `Owners::Add`, and call the method `run` on it.
|
78
|
-
|
79
|
-
Help output:
|
80
|
-
|
81
|
-
```txt
|
82
|
-
Usage: owners add [owners] [options]
|
83
|
-
|
84
|
-
Summary:
|
77
|
+
# Running this, e.g. using `bin/owners add one,two --to group` will instantiate the
|
78
|
+
# class `Owners::Add`, and call the method `run` on it.
|
85
79
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
Use this command to add one or more owners to an existing
|
91
|
-
owner group.
|
80
|
+
# e.g. bin/owners
|
81
|
+
#
|
82
|
+
# args normally would be ARGV
|
83
|
+
args = %w(add one --to group)
|
92
84
|
|
93
|
-
|
85
|
+
Cl.new('owners').run(args)
|
94
86
|
|
95
|
-
|
87
|
+
# Output:
|
88
|
+
#
|
89
|
+
# {:owner=>"one", :to=>"group", :to?=>true, :args=>["one"], :opts=>{:to=>"group"}}
|
96
90
|
|
97
|
-
|
91
|
+
Cl.new('owners').run(%w(add --help))
|
98
92
|
|
99
|
-
|
93
|
+
# Output:
|
94
|
+
#
|
95
|
+
# Usage: owners add [owner] [options]
|
96
|
+
#
|
97
|
+
# Summary:
|
98
|
+
#
|
99
|
+
# Add one or more owners to an existing owner group
|
100
|
+
#
|
101
|
+
# Description:
|
102
|
+
#
|
103
|
+
# Use this command to add one or more owners to an existing
|
104
|
+
# owner group.
|
105
|
+
#
|
106
|
+
# [...]
|
107
|
+
#
|
108
|
+
# Arguments:
|
109
|
+
#
|
110
|
+
# owner type: string
|
111
|
+
#
|
112
|
+
# Options:
|
113
|
+
#
|
114
|
+
# -t --to TO An existing owner group (type: string)
|
115
|
+
# --help Get help on this command
|
100
116
|
|
101
|
-
-t --to TO An existing owner group (type: string, required: true)
|
102
|
-
--help Get help on this command (type: flag)
|
103
117
|
```
|
104
118
|
|
105
119
|
### Command Registry
|
@@ -112,20 +126,17 @@ to decouple looking up command classes from their Ruby namespace.
|
|
112
126
|
For example:
|
113
127
|
|
114
128
|
```ruby
|
115
|
-
module
|
116
|
-
class
|
117
|
-
register :one
|
129
|
+
module Cmd
|
130
|
+
class One < Cl::Cmd
|
118
131
|
end
|
119
|
-
end
|
120
132
|
|
121
|
-
|
122
|
-
class Cmd < Cl::Cmd
|
123
|
-
register :two
|
133
|
+
class Two < Cl::Cmd
|
124
134
|
end
|
125
135
|
end
|
126
136
|
|
127
|
-
Cl::Cmd[:one] # => One
|
128
|
-
Cl::Cmd[:two] # => Two
|
137
|
+
p Cl::Cmd[:one] # => Cmd::One
|
138
|
+
p Cl::Cmd[:two] # => Cmd::Two
|
139
|
+
|
129
140
|
```
|
130
141
|
|
131
142
|
Commands auto register themselves with the underscored name of the last part of
|
@@ -158,10 +169,10 @@ would recognize and run the following commands:
|
|
158
169
|
|
159
170
|
```
|
160
171
|
$ bin/run one something else
|
161
|
-
# instantiates One, passing the args array `["something", "else"]`, and calls `run`
|
172
|
+
# instantiates One, passing the args array `["something", "else"]`, and calls the instance method `run`
|
162
173
|
|
163
|
-
$ bin/run two
|
164
|
-
# instantiates
|
174
|
+
$ bin/run two
|
175
|
+
# instantiates Two, passing an empty args arry `[]`, and calls the instance method `run`
|
165
176
|
```
|
166
177
|
|
167
178
|
The default runner also supports nested namespaces, and checks for command classes
|
@@ -171,47 +182,61 @@ with keys separated by colons. For instance:
|
|
171
182
|
module Git
|
172
183
|
class Pull < Cl::Cmd
|
173
184
|
register :'git:pull'
|
174
|
-
end
|
175
|
-
end
|
176
185
|
|
177
|
-
|
178
|
-
|
179
|
-
|
186
|
+
def run
|
187
|
+
p cmd: registry_key, args: args
|
188
|
+
end
|
180
189
|
end
|
181
190
|
end
|
182
|
-
```
|
183
191
|
|
184
|
-
With
|
185
|
-
`bin/
|
192
|
+
# With this class registered (and assuming the executable that calls `Cl` is
|
193
|
+
# `bin/run`) the default runner would recognize and run it:
|
194
|
+
#
|
195
|
+
# $ bin/run git:pull master # instantiates Git::Pull, and passes ["master"] as args
|
196
|
+
# $ bin/run git pull master # does the same
|
186
197
|
|
187
|
-
|
188
|
-
|
189
|
-
|
198
|
+
Cl.new('run').run(%w(git:pull master))
|
199
|
+
# Output:
|
200
|
+
#
|
201
|
+
# {:cmd=>:"git:pull", :args=>["master"]}
|
202
|
+
|
203
|
+
Cl.new('run').run(%w(git pull master))
|
204
|
+
# Output:
|
205
|
+
#
|
206
|
+
# {:cmd=>:"git:pull", :args=>["master"]}
|
190
207
|
|
191
|
-
$ bin/git push:master # instantiates Git::Push, and passes ["master"] as args
|
192
|
-
$ bin/git push master # does the same
|
193
208
|
```
|
194
209
|
|
195
210
|
Runners are registered on the module `Cl::Runner`. It is possible to register custom
|
196
211
|
runners, and use them by passing the option `runner` to `Cl.new`:
|
197
212
|
|
198
|
-
```
|
199
|
-
|
200
|
-
|
201
|
-
|
202
|
-
# anywhere in your library
|
203
|
-
class Runner
|
204
|
-
Cl::Runner.register :custom, self
|
205
|
-
|
206
|
-
def initialize(ctx, args)
|
207
|
-
# ...
|
208
|
-
end
|
213
|
+
```ruby
|
214
|
+
module Git
|
215
|
+
class Pull < Cl::Cmd
|
216
|
+
register :'git:pull'
|
209
217
|
|
210
|
-
|
211
|
-
|
212
|
-
|
218
|
+
def run
|
219
|
+
p cmd: registry_key, args: args
|
220
|
+
end
|
213
221
|
end
|
214
222
|
end
|
223
|
+
|
224
|
+
# With this class registered (and assuming the executable that calls `Cl` is
|
225
|
+
# `bin/run`) the default runner would recognize and run it:
|
226
|
+
#
|
227
|
+
# $ bin/run git:pull master # instantiates Git::Pull, and passes ["master"] as args
|
228
|
+
# $ bin/run git pull master # does the same
|
229
|
+
|
230
|
+
Cl.new('run').run(%w(git:pull master))
|
231
|
+
# Output:
|
232
|
+
#
|
233
|
+
# {:cmd=>:"git:pull", :args=>["master"]}
|
234
|
+
|
235
|
+
Cl.new('run').run(%w(git pull master))
|
236
|
+
# Output:
|
237
|
+
#
|
238
|
+
# {:cmd=>:"git:pull", :args=>["master"]}
|
239
|
+
|
215
240
|
```
|
216
241
|
|
217
242
|
See `Cl::Runner::Default` for more details.
|
@@ -237,7 +262,7 @@ Commands are classes that are derived from the base class `Cl::Cmd`.
|
|
237
262
|
|
238
263
|
The description, summary, and examples are used in the help output.
|
239
264
|
|
240
|
-
```
|
265
|
+
```ruby
|
241
266
|
module Owners
|
242
267
|
class Add < Cl::Cmd
|
243
268
|
summary 'Add one or more owners to an existing owner group'
|
@@ -258,6 +283,36 @@ module Owners
|
|
258
283
|
str
|
259
284
|
end
|
260
285
|
end
|
286
|
+
|
287
|
+
Cl.new('owners').run(%w(add --help))
|
288
|
+
|
289
|
+
# Output:
|
290
|
+
#
|
291
|
+
# Usage: owners add [options]
|
292
|
+
#
|
293
|
+
# Summary:
|
294
|
+
#
|
295
|
+
# Add one or more owners to an existing owner group
|
296
|
+
#
|
297
|
+
# Description:
|
298
|
+
#
|
299
|
+
# Use this command to add one or more owners to an existing
|
300
|
+
# owner group.
|
301
|
+
#
|
302
|
+
# Options:
|
303
|
+
#
|
304
|
+
# --help Get help on this command
|
305
|
+
#
|
306
|
+
# Examples:
|
307
|
+
#
|
308
|
+
# Adding a single user to the group admins:
|
309
|
+
#
|
310
|
+
# owners add user --to admins
|
311
|
+
#
|
312
|
+
# Adding a several users at once:
|
313
|
+
#
|
314
|
+
# owners add one two three --to admins
|
315
|
+
|
261
316
|
```
|
262
317
|
|
263
318
|
#### Abstract
|
@@ -831,12 +886,14 @@ end
|
|
831
886
|
|
832
887
|
Cl.new('owners').run(%w(add --help))
|
833
888
|
|
834
|
-
#
|
889
|
+
# Output:
|
835
890
|
#
|
836
|
-
#
|
891
|
+
# Usage: owners add [options]
|
837
892
|
#
|
838
|
-
#
|
839
|
-
#
|
893
|
+
# Options:
|
894
|
+
#
|
895
|
+
# --to GROUP type: string, note: needs to be a group
|
896
|
+
# --help Get help on this command
|
840
897
|
|
841
898
|
```
|
842
899
|
|
data/examples/README.md
ADDED
@@ -0,0 +1,22 @@
|
|
1
|
+
# Cl Examples
|
2
|
+
|
3
|
+
This directory contains examples for using `cl`.
|
4
|
+
|
5
|
+
Examples are executable, so you can try them out and experiment with them. E.g.:
|
6
|
+
|
7
|
+
```
|
8
|
+
git clone https://github.com/svenfuchs/cl.git /tmp/cl
|
9
|
+
cd /tmp/cl
|
10
|
+
examples/gem
|
11
|
+
```
|
12
|
+
|
13
|
+
Examples are generated and verified by running:
|
14
|
+
|
15
|
+
```
|
16
|
+
bundle exec bin/examples
|
17
|
+
```
|
18
|
+
|
19
|
+
This command runs on [on Travis CI](https://github.com/svenfuchs/cl/blob/master/.travis.yml#L14)
|
20
|
+
in order to guarantee that all examples are up to date,
|
21
|
+
but also can be run in order to add or update examples.
|
22
|
+
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,70 @@
|
|
1
|
+
<%= run sq(<<-'rb')
|
2
|
+
require 'cl'
|
3
|
+
|
4
|
+
# e.g. lib/owners/add.rb
|
5
|
+
module Owners
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
summary 'Add one or more owners to an existing owner group'
|
8
|
+
|
9
|
+
description <<~str
|
10
|
+
Use this command to add one or more owners to an existing
|
11
|
+
owner group.
|
12
|
+
|
13
|
+
[...]
|
14
|
+
str
|
15
|
+
|
16
|
+
args :owner
|
17
|
+
|
18
|
+
opt '-t', '--to TO', 'An existing owner group'
|
19
|
+
|
20
|
+
def run
|
21
|
+
# implement adding the owner as given in `owner` (as well as `args`)
|
22
|
+
# to the group given in `to` (as well as `opts[:to]`).
|
23
|
+
p owner: owner, to: to, to?: to?, args: args, opts: opts
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rb
|
28
|
+
-%>
|
29
|
+
|
30
|
+
# Running this, e.g. using `bin/owners add one,two --to group` will instantiate the
|
31
|
+
# class `Owners::Add`, and call the method `run` on it.
|
32
|
+
|
33
|
+
<%= run sq(<<-'rb')
|
34
|
+
# e.g. bin/owners
|
35
|
+
#
|
36
|
+
# args normally would be ARGV
|
37
|
+
args = %w(add one --to group)
|
38
|
+
|
39
|
+
Cl.new('owners').run(args)
|
40
|
+
rb
|
41
|
+
-%>
|
42
|
+
|
43
|
+
<%= out '{:owner=>"one", :to=>"group", :to?=>true, :args=>["one"], :opts=>{:to=>"group"}}' %>
|
44
|
+
|
45
|
+
<%= run "Cl.new('owners').run(%w(add --help))" %>
|
46
|
+
|
47
|
+
<%= out sq(<<-'str')
|
48
|
+
Usage: owners add [owner] [options]
|
49
|
+
|
50
|
+
Summary:
|
51
|
+
|
52
|
+
Add one or more owners to an existing owner group
|
53
|
+
|
54
|
+
Description:
|
55
|
+
|
56
|
+
Use this command to add one or more owners to an existing
|
57
|
+
owner group.
|
58
|
+
|
59
|
+
[...]
|
60
|
+
|
61
|
+
Arguments:
|
62
|
+
|
63
|
+
owner type: string
|
64
|
+
|
65
|
+
Options:
|
66
|
+
|
67
|
+
-t --to TO An existing owner group (type: string)
|
68
|
+
--help Get help on this command
|
69
|
+
str
|
70
|
+
%>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,58 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
<%= run sq(<<-'rb')
|
5
|
+
require 'cl'
|
6
|
+
|
7
|
+
module Owners
|
8
|
+
class Add < Cl::Cmd
|
9
|
+
summary 'Add one or more owners to an existing owner group'
|
10
|
+
|
11
|
+
description <<~str
|
12
|
+
Use this command to add one or more owners to an existing
|
13
|
+
owner group.
|
14
|
+
str
|
15
|
+
|
16
|
+
examples <<~str
|
17
|
+
Adding a single user to the group admins:
|
18
|
+
|
19
|
+
owners add user --to admins
|
20
|
+
|
21
|
+
Adding a several users at once:
|
22
|
+
|
23
|
+
owners add one two three --to admins
|
24
|
+
str
|
25
|
+
end
|
26
|
+
end
|
27
|
+
rb
|
28
|
+
-%>
|
29
|
+
|
30
|
+
<%= run "Cl.new('owners').run(%w(add --help))" %>
|
31
|
+
|
32
|
+
<%= out sq(<<-'str')
|
33
|
+
Usage: owners add [options]
|
34
|
+
|
35
|
+
Summary:
|
36
|
+
|
37
|
+
Add one or more owners to an existing owner group
|
38
|
+
|
39
|
+
Description:
|
40
|
+
|
41
|
+
Use this command to add one or more owners to an existing
|
42
|
+
owner group.
|
43
|
+
|
44
|
+
Options:
|
45
|
+
|
46
|
+
--help Get help on this command
|
47
|
+
|
48
|
+
Examples:
|
49
|
+
|
50
|
+
Adding a single user to the group admins:
|
51
|
+
|
52
|
+
owners add user --to admins
|
53
|
+
|
54
|
+
Adding a several users at once:
|
55
|
+
|
56
|
+
owners add one two three --to admins
|
57
|
+
str
|
58
|
+
%>
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,16 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
<%= run sq(<<-'rb')
|
5
|
+
module Cmd
|
6
|
+
class One < Cl::Cmd
|
7
|
+
end
|
8
|
+
|
9
|
+
class Two < Cl::Cmd
|
10
|
+
end
|
11
|
+
end
|
12
|
+
rb
|
13
|
+
-%>
|
14
|
+
|
15
|
+
<%= run 'p Cl::Cmd[:one]' %> <%= out 'Cmd::One', short: true %>
|
16
|
+
<%= run 'p Cl::Cmd[:two]' %> <%= out 'Cmd::Two', short: true %>
|
File without changes
|
File without changes
|
File without changes
|
@@ -0,0 +1,27 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
<%= run sq(<<-'rb')
|
5
|
+
module Git
|
6
|
+
class Pull < Cl::Cmd
|
7
|
+
register :'git:pull'
|
8
|
+
|
9
|
+
def run
|
10
|
+
p cmd: registry_key, args: args
|
11
|
+
end
|
12
|
+
end
|
13
|
+
end
|
14
|
+
rb
|
15
|
+
-%>
|
16
|
+
|
17
|
+
# With this class registered (and assuming the executable that calls `Cl` is
|
18
|
+
# `bin/run`) the default runner would recognize and run it:
|
19
|
+
#
|
20
|
+
# $ bin/run git:pull master # instantiates Git::Pull, and passes ["master"] as args
|
21
|
+
# $ bin/run git pull master # does the same
|
22
|
+
|
23
|
+
<%= run "Cl.new('run').run(%w(git:pull master))" %>
|
24
|
+
<%= out '{:cmd=>:"git:pull", :args=>["master"]}' %>
|
25
|
+
|
26
|
+
<%= run "Cl.new('run').run(%w(git pull master))" %>
|
27
|
+
<%= out '{:cmd=>:"git:pull", :args=>["master"]}' %>
|
@@ -0,0 +1,25 @@
|
|
1
|
+
<%= run sq(<<-'rb')
|
2
|
+
# anywhere in your library
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Runner
|
7
|
+
Cl::Runner.register :custom, self
|
8
|
+
|
9
|
+
def initialize(ctx, args)
|
10
|
+
# ...
|
11
|
+
end
|
12
|
+
|
13
|
+
def run
|
14
|
+
const = identify_cmd_class_from_args
|
15
|
+
const.new(ctx, args).run
|
16
|
+
end
|
17
|
+
end
|
18
|
+
rb
|
19
|
+
-%>
|
20
|
+
|
21
|
+
# in bin/run
|
22
|
+
Cl.new('run', runner: :custom).run(ARGV)
|
23
|
+
|
24
|
+
<% run "p Cl.new('run', runner: :custom).runner([]).class" %>
|
25
|
+
<% out 'Runner' %>
|
File without changes
|
File without changes
|
File without changes
|