cl 0.1.12 → 0.1.13
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/CHANGELOG.md +5 -3
- data/Gemfile.lock +2 -2
- data/NOTES.md +12 -8
- data/README.md +897 -13
- data/examples/readme/alias +22 -0
- data/examples/readme/arg +16 -0
- data/examples/readme/arg_array +16 -0
- data/examples/readme/arg_type +18 -0
- data/examples/readme/args_splat +43 -0
- data/examples/readme/array +18 -0
- data/examples/readme/default +18 -0
- data/examples/readme/deprecated +21 -0
- data/examples/readme/deprecated_alias +20 -0
- data/examples/readme/downcase +18 -0
- data/examples/readme/enum +26 -0
- data/examples/readme/example +17 -0
- data/examples/readme/format +29 -0
- data/examples/readme/internal +18 -0
- data/examples/readme/opts +29 -0
- data/examples/readme/opts_block +26 -0
- data/examples/readme/range +29 -0
- data/examples/readme/required +29 -0
- data/examples/readme/requireds +36 -0
- data/examples/readme/requires +32 -0
- data/examples/readme/see +21 -0
- data/examples/readme/type +22 -0
- data/lib/cl.rb +26 -66
- data/lib/cl/arg.rb +9 -5
- data/lib/cl/cast.rb +5 -1
- data/lib/cl/cmd.rb +11 -49
- data/lib/cl/ctx.rb +3 -5
- data/lib/cl/dsl.rb +176 -0
- data/lib/cl/errors.rb +73 -0
- data/lib/cl/help/cmd.rb +8 -3
- data/lib/cl/helper.rb +8 -0
- data/lib/cl/opt.rb +13 -0
- data/lib/cl/opts.rb +27 -8
- data/lib/cl/runner.rb +10 -0
- data/lib/cl/runner/default.rb +22 -2
- data/lib/cl/runner/multi.rb +6 -4
- data/lib/cl/ui.rb +11 -2
- data/lib/cl/version.rb +1 -1
- metadata +27 -2
@@ -0,0 +1,22 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', alias: :group
|
8
|
+
|
9
|
+
def run
|
10
|
+
p opts, to, to?, group, group?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# {"to" => "one"}
|
19
|
+
# "one"
|
20
|
+
# true
|
21
|
+
# "one"
|
22
|
+
# true
|
data/examples/readme/arg
ADDED
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Cmd < Cl::Cmd
|
7
|
+
arg :one, type: :integer
|
8
|
+
arg :two, type: :float
|
9
|
+
arg :three, type: :boolean
|
10
|
+
|
11
|
+
def run
|
12
|
+
p [one.class, two.class, three.class]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
Cl.new('owners').run(%w(cmd 1 2.1 yes))
|
17
|
+
|
18
|
+
# => [Integer, Float, TrueClass]
|
@@ -0,0 +1,43 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Lft < Cl::Cmd
|
7
|
+
arg :a, type: :array, splat: true
|
8
|
+
arg :b
|
9
|
+
arg :c
|
10
|
+
|
11
|
+
def run
|
12
|
+
p [a, b, c]
|
13
|
+
end
|
14
|
+
end
|
15
|
+
|
16
|
+
class Mid < Cl::Cmd
|
17
|
+
arg :a
|
18
|
+
arg :b, type: :array, splat: true
|
19
|
+
arg :c
|
20
|
+
|
21
|
+
def run
|
22
|
+
p [a, b, c]
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
class Rgt < Cl::Cmd
|
27
|
+
arg :a
|
28
|
+
arg :b
|
29
|
+
arg :c, type: :array, splat: true
|
30
|
+
|
31
|
+
def run
|
32
|
+
p [a, b, c]
|
33
|
+
end
|
34
|
+
end
|
35
|
+
|
36
|
+
Cl.new('splat').run(%w(lft 1 2 3 4 5))
|
37
|
+
Cl.new('splat').run(%w(mid 1 2 3 4 5))
|
38
|
+
Cl.new('splat').run(%w(rgt 1 2 3 4 5))
|
39
|
+
|
40
|
+
# =>
|
41
|
+
# [["1", "2", "3"], "4", "5"]
|
42
|
+
# ["1", ["2", "3", "4"], "5"]
|
43
|
+
# ["1", "2", ["3", "4", "5"]]
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', type: :array
|
8
|
+
|
9
|
+
def run
|
10
|
+
p to
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one --to two))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# ["one", "two"]
|
@@ -0,0 +1,21 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP'
|
8
|
+
opt '--target GROUP', deprecated: 'Deprecated: --target'
|
9
|
+
|
10
|
+
def run
|
11
|
+
p to, deprecated_opts
|
12
|
+
end
|
13
|
+
end
|
14
|
+
|
15
|
+
Cl.new('owners').run(%w(add --target one))
|
16
|
+
|
17
|
+
# Output:
|
18
|
+
#
|
19
|
+
# "one"
|
20
|
+
# {:target=>'Deprecated: --target'}
|
21
|
+
|
@@ -0,0 +1,20 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', alias: :target, deprecated: :target
|
8
|
+
|
9
|
+
def run
|
10
|
+
p to, deprecated_opts
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --target one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# "one"
|
19
|
+
# {:target=>:to}
|
20
|
+
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', enum: %w(one two)
|
8
|
+
|
9
|
+
def run
|
10
|
+
p to
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# "one"
|
19
|
+
|
20
|
+
Cl.new('owners').run(%w(add --to unknown))
|
21
|
+
|
22
|
+
# Unknown value: to=unknown (known values: one, two)
|
23
|
+
#
|
24
|
+
# Usage: enum add [options]
|
25
|
+
#
|
26
|
+
# Options: ...
|
@@ -0,0 +1,17 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', example: 'group-one'
|
8
|
+
end
|
9
|
+
|
10
|
+
Cl.new('owners').run(%w(add --help))
|
11
|
+
|
12
|
+
# Usage: example add [options]
|
13
|
+
#
|
14
|
+
# Options:
|
15
|
+
#
|
16
|
+
# --to GROUP type: string, e.g.: group-one
|
17
|
+
# --help Get help on this command
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', format: /^\w+$/
|
8
|
+
|
9
|
+
def run
|
10
|
+
p to
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# "one"
|
19
|
+
|
20
|
+
Cl.new('owners').run(['add', '--to', 'does not match!'])
|
21
|
+
|
22
|
+
Invalid format: to (format: /^\w+$/)
|
23
|
+
|
24
|
+
Usage: format add [options]
|
25
|
+
|
26
|
+
Options:
|
27
|
+
|
28
|
+
--to GROUP type: string, format: /^\w+$/
|
29
|
+
--help Get help on this command
|
@@ -0,0 +1,18 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP'
|
8
|
+
opt '--hidden', internal: true
|
9
|
+
end
|
10
|
+
|
11
|
+
Cl.new('owners').run(%w(add --help))
|
12
|
+
|
13
|
+
# Usage: example add [options]
|
14
|
+
#
|
15
|
+
# Options:
|
16
|
+
#
|
17
|
+
# --to GROUP type: string, e.g.: group-one
|
18
|
+
# --help Get help on this command
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', 'Target group to add owners to'
|
8
|
+
|
9
|
+
def run
|
10
|
+
p opts, to, to?
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# {"to" => "one"}
|
19
|
+
# "one"
|
20
|
+
# true
|
21
|
+
|
22
|
+
Cl.new('owners').run(%w(add --help))
|
23
|
+
|
24
|
+
# Usage: opts add [options]
|
25
|
+
#
|
26
|
+
# Options:
|
27
|
+
#
|
28
|
+
# --to GROUP Target group to add owners to (type: string)
|
29
|
+
# --help Get help on this command
|
@@ -0,0 +1,26 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
# depending on its arity the block can receive:
|
8
|
+
#
|
9
|
+
# * value
|
10
|
+
# * value, name
|
11
|
+
# * value, name, type
|
12
|
+
# * value, name, type, opts
|
13
|
+
opt '--to GROUP' do |value|
|
14
|
+
opts[:to] = "#{value.upcase}!"
|
15
|
+
end
|
16
|
+
|
17
|
+
def run
|
18
|
+
p to
|
19
|
+
end
|
20
|
+
end
|
21
|
+
|
22
|
+
Cl.new('owners').run(%w(add --to one))
|
23
|
+
|
24
|
+
# Output:
|
25
|
+
#
|
26
|
+
# "ONE!"
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--retries COUNT', type: :integer, min: 1, max: 5
|
8
|
+
|
9
|
+
def run
|
10
|
+
p retries
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --retries 1))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# 1
|
19
|
+
|
20
|
+
Cl.new('owners').run(%w(add --retries 10))
|
21
|
+
|
22
|
+
# Out of range: retries (max: 5)
|
23
|
+
#
|
24
|
+
# Usage: max add [options]
|
25
|
+
#
|
26
|
+
# Options:
|
27
|
+
#
|
28
|
+
# --retries COUNT type: integer, min: 1, max: 5
|
29
|
+
# --help Get help on this command
|
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
opt '--to GROUP', required: true
|
8
|
+
|
9
|
+
def run
|
10
|
+
p to
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
Cl.new('owners').run(%w(add --to one))
|
15
|
+
|
16
|
+
# Output:
|
17
|
+
#
|
18
|
+
# "one"
|
19
|
+
|
20
|
+
Cl.new('owners').run(%w(add))
|
21
|
+
|
22
|
+
# Missing required option: to
|
23
|
+
#
|
24
|
+
# Usage: required add [options]
|
25
|
+
#
|
26
|
+
# Options:
|
27
|
+
#
|
28
|
+
# --to GROUP type: string, required: true
|
29
|
+
# --help Get help on this command
|
@@ -0,0 +1,36 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
$: << File.expand_path('lib')
|
3
|
+
|
4
|
+
require 'cl'
|
5
|
+
|
6
|
+
class Add < Cl::Cmd
|
7
|
+
# read DNF, i.e. "apikey OR username AND password
|
8
|
+
required :api_key, [:username, :password]
|
9
|
+
|
10
|
+
opt '--api_key KEY'
|
11
|
+
opt '--username NAME'
|
12
|
+
opt '--password PASS'
|
13
|
+
|
14
|
+
def run
|
15
|
+
p to, retries
|
16
|
+
end
|
17
|
+
end
|
18
|
+
|
19
|
+
Cl.new('owners').run(%w(add --to one --retries 1))
|
20
|
+
|
21
|
+
# Output:
|
22
|
+
#
|
23
|
+
# "one"
|
24
|
+
# 1
|
25
|
+
|
26
|
+
Cl.new('owners').run(%w(add --retries 1))
|
27
|
+
|
28
|
+
# Missing option: to (required by retries)
|
29
|
+
#
|
30
|
+
# Usage: requires add [options]
|
31
|
+
#
|
32
|
+
# Options:
|
33
|
+
#
|
34
|
+
# --to GROUP type: string
|
35
|
+
# --retries INT type: string, requires: to
|
36
|
+
# --help Get help on this command
|