cl 0.1.28 → 1.0.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.
Files changed (73) hide show
  1. checksums.yaml +5 -5
  2. data/Gemfile +1 -0
  3. data/Gemfile.lock +19 -1
  4. data/NOTES.md +2 -0
  5. data/README.md +210 -142
  6. data/examples/args/cast +53 -41
  7. data/examples/args/opts +72 -14
  8. data/examples/args/required +28 -14
  9. data/examples/args/splat +29 -32
  10. data/examples/gem +26 -37
  11. data/examples/heroku +15 -16
  12. data/examples/rakeish +13 -15
  13. data/examples/readme/abstract +6 -5
  14. data/examples/readme/alias +4 -7
  15. data/examples/readme/arg +4 -2
  16. data/examples/readme/arg_array +4 -2
  17. data/examples/readme/arg_type +3 -1
  18. data/examples/readme/args_splat +13 -4
  19. data/examples/readme/default +2 -2
  20. data/examples/readme/deprecated +3 -6
  21. data/examples/readme/deprecated_alias +2 -4
  22. data/examples/readme/downcase +2 -2
  23. data/examples/readme/enum +10 -5
  24. data/examples/readme/example +6 -4
  25. data/examples/readme/format +9 -7
  26. data/examples/readme/internal +8 -4
  27. data/examples/readme/negate +20 -5
  28. data/examples/readme/node +19 -0
  29. data/examples/readme/opts +8 -8
  30. data/examples/readme/opts_block +4 -3
  31. data/examples/readme/range +9 -7
  32. data/examples/readme/required +9 -7
  33. data/examples/readme/requireds +26 -18
  34. data/examples/readme/requires +13 -14
  35. data/examples/readme/secret +7 -9
  36. data/examples/readme/see +6 -8
  37. data/examples/readme/type +2 -6
  38. data/examples/src/args/cast.erb.rb +96 -0
  39. data/examples/src/args/opts.erb.rb +96 -0
  40. data/examples/src/args/required.erb.rb +61 -0
  41. data/examples/src/args/splat.erb.rb +55 -0
  42. data/examples/src/gem.erb.rb +95 -0
  43. data/examples/src/heroku.erb.rb +47 -0
  44. data/examples/src/rakeish.erb.rb +54 -0
  45. data/examples/src/readme/abstract.erb.rb +25 -0
  46. data/examples/src/readme/alias.erb.rb +20 -0
  47. data/examples/src/readme/arg.erb.rb +19 -0
  48. data/examples/src/readme/arg_array.erb.rb +19 -0
  49. data/examples/src/readme/arg_type.erb.rb +21 -0
  50. data/examples/src/readme/args_splat.erb.rb +49 -0
  51. data/examples/src/readme/array.erb.rb +19 -0
  52. data/examples/src/readme/default.erb.rb +19 -0
  53. data/examples/src/readme/deprecated.erb.rb +19 -0
  54. data/examples/src/readme/deprecated_alias.erb.rb +19 -0
  55. data/examples/src/readme/downcase.erb.rb +19 -0
  56. data/examples/src/readme/enum.erb.rb +33 -0
  57. data/examples/src/readme/example.erb.rb +23 -0
  58. data/examples/src/readme/format.erb.rb +33 -0
  59. data/examples/src/readme/internal.erb.rb +26 -0
  60. data/examples/src/readme/negate.erb.rb +35 -0
  61. data/examples/src/readme/node.erb.rb +23 -0
  62. data/examples/src/readme/opts.erb.rb +31 -0
  63. data/examples/src/readme/opts_block.erb.rb +28 -0
  64. data/examples/src/readme/range.erb.rb +33 -0
  65. data/examples/src/readme/required.erb.rb +33 -0
  66. data/examples/src/readme/requireds.erb.rb +44 -0
  67. data/examples/src/readme/requires.erb.rb +33 -0
  68. data/examples/src/readme/secret.erb.rb +20 -0
  69. data/examples/src/readme/see.erb.rb +23 -0
  70. data/examples/src/readme/type.erb.rb +19 -0
  71. data/lib/cl/ui.rb +2 -2
  72. data/lib/cl/version.rb +1 -1
  73. metadata +40 -10
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', 'Target group to add owners to'
8
8
 
9
9
  def run
10
- p opts, to, to?
10
+ p opts: opts, to: to, to?: to?
11
11
  end
12
12
  end
13
13
 
@@ -15,15 +15,15 @@ Cl.new('owners').run(%w(add --to one))
15
15
 
16
16
  # Output:
17
17
  #
18
- # {"to" => "one"}
19
- # "one"
20
- # true
18
+ # {:opts=>{:to=>"one"}, :to=>"one", :to?=>true}
21
19
 
22
20
  Cl.new('owners').run(%w(add --help))
23
21
 
24
- # Usage: opts add [options]
22
+ # Output:
23
+ #
24
+ # Usage: owners add [options]
25
25
  #
26
- # Options:
26
+ # Options:
27
27
  #
28
- # --to GROUP Target group to add owners to (type: string)
29
- # --help Get help on this command
28
+ # --to GROUP Target group to add owners to (type: string)
29
+ # --help Get help on this command
@@ -11,11 +11,11 @@ class Add < Cl::Cmd
11
11
  # * value, name, type
12
12
  # * value, name, type, opts
13
13
  opt '--to GROUP' do |value|
14
- opts[:to] = "#{value.upcase}!"
14
+ opts[:to] = "group-#{value}"
15
15
  end
16
16
 
17
17
  def run
18
- p to
18
+ p to: to
19
19
  end
20
20
  end
21
21
 
@@ -23,4 +23,5 @@ Cl.new('owners').run(%w(add --to one))
23
23
 
24
24
  # Output:
25
25
  #
26
- # "ONE!"
26
+ # {:to=>"group-one"}
27
+
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--retries COUNT', type: :integer, min: 1, max: 5
8
8
 
9
9
  def run
10
- p retries
10
+ p retries: retries
11
11
  end
12
12
  end
13
13
 
@@ -15,15 +15,17 @@ Cl.new('owners').run(%w(add --retries 1))
15
15
 
16
16
  # Output:
17
17
  #
18
- # 1
18
+ # {:retries=>1}
19
19
 
20
20
  Cl.new('owners').run(%w(add --retries 10))
21
21
 
22
- # Out of range: retries (max: 5)
22
+ # Output:
23
+ #
24
+ # Out of range: retries (min: 1, max: 5)
23
25
  #
24
- # Usage: max add [options]
26
+ # Usage: owners add [options]
25
27
  #
26
- # Options:
28
+ # Options:
27
29
  #
28
- # --retries COUNT type: integer, min: 1, max: 5
29
- # --help Get help on this command
30
+ # --retries COUNT type: integer, min: 1, max: 5
31
+ # --help Get help on this command
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', required: true
8
8
 
9
9
  def run
10
- p to
10
+ p to: to
11
11
  end
12
12
  end
13
13
 
@@ -15,15 +15,17 @@ Cl.new('owners').run(%w(add --to one))
15
15
 
16
16
  # Output:
17
17
  #
18
- # "one"
18
+ # {:to=>"one"}
19
19
 
20
20
  Cl.new('owners').run(%w(add))
21
21
 
22
- # Missing required option: to
22
+ # Output:
23
+ #
24
+ # Missing required option: to
23
25
  #
24
- # Usage: required add [options]
26
+ # Usage: owners add [options]
25
27
  #
26
- # Options:
28
+ # Options:
27
29
  #
28
- # --to GROUP type: string, required: true
29
- # --help Get help on this command
30
+ # --to GROUP type: string, required: true
31
+ # --help Get help on this command
@@ -1,36 +1,44 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path('lib')
3
3
 
4
- require 'cl'
5
-
6
4
  class Add < Cl::Cmd
7
- # read DNF, i.e. "apikey OR username AND password
8
- required :api_key, [:username, :password]
5
+ # read DNF, i.e. "token OR user AND pass
6
+ required :token, [:user, :pass]
9
7
 
10
- opt '--api_key KEY'
11
- opt '--username NAME'
12
- opt '--password PASS'
8
+ opt '--token TOKEN'
9
+ opt '--user NAME'
10
+ opt '--pass PASS'
13
11
 
14
12
  def run
15
- p to, retries
13
+ p token: token, user: user, pass: pass
16
14
  end
17
15
  end
18
16
 
19
- Cl.new('owners').run(%w(add --to one --retries 1))
17
+ Cl.new('owners').run(%w(add --token token))
18
+
19
+ # Output:
20
+ #
21
+ # {:token=>"token", :user=>nil, :pass=>nil}
22
+
23
+ Cl.new('owners').run(%w(add --user user --pass pass))
20
24
 
21
25
  # Output:
22
26
  #
23
- # "one"
24
- # 1
27
+ # {:token=>nil, :user=>"user", :pass=>"pass"}
25
28
 
26
- Cl.new('owners').run(%w(add --retries 1))
29
+ Cl.new('owners').run(%w(add))
27
30
 
28
- # Missing option: to (required by retries)
31
+ # Output:
32
+ #
33
+ # Missing options: token, or user and pass
34
+ #
35
+ # Usage: owners add [options]
29
36
  #
30
- # Usage: requires add [options]
37
+ # Options:
31
38
  #
32
- # Options:
39
+ # Either token, or user and pass are required.
33
40
  #
34
- # --to GROUP type: string
35
- # --retries INT type: string, requires: to
36
- # --help Get help on this command
41
+ # --token TOKEN type: string
42
+ # --user NAME type: string
43
+ # --pass PASS type: string
44
+ # --help Get help on this command
@@ -1,32 +1,31 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path('lib')
3
3
 
4
- require 'cl'
5
-
6
4
  class Add < Cl::Cmd
7
5
  opt '--to GROUP'
8
- opt '--retries INT', requires: :to
6
+ opt '--other GROUP', requires: :to
9
7
 
10
8
  def run
11
- p to, retries
9
+ p to: to, other: other
12
10
  end
13
11
  end
14
12
 
15
- Cl.new('owners').run(%w(add --to one --retries 1))
13
+ Cl.new('owners').run(%w(add --to one --other two))
16
14
 
17
15
  # Output:
18
16
  #
19
- # "one"
20
- # 1
17
+ # {:to=>"one", :other=>"two"}
21
18
 
22
- Cl.new('owners').run(%w(add --retries 1))
19
+ Cl.new('owners').run(%w(add --other two))
23
20
 
24
- # Missing option: to (required by retries)
21
+ # Output:
22
+ #
23
+ # Missing option: to (required by other)
25
24
  #
26
- # Usage: requires add [options]
25
+ # Usage: owners add [options]
27
26
  #
28
- # Options:
27
+ # Options:
29
28
  #
30
- # --to GROUP type: string
31
- # --retries INT type: string, requires: to
32
- # --help Get help on this command
29
+ # --to GROUP type: string
30
+ # --other GROUP type: string, requires: to
31
+ # --help Get help on this command
@@ -1,21 +1,19 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path('lib')
3
3
 
4
- require 'cl'
5
-
6
4
  class Add < Cl::Cmd
7
- opt '--to GROUP'
8
- opt '--password PASS', secret: true
5
+ opt '--pass PASS', secret: true
9
6
 
10
7
  def run
11
- puts [:secret?, self.class.opts[:password].secret?].join(' ')
12
- puts [:tainted?, password.tainted?].join(' ')
8
+ p(
9
+ secret?: self.class.opts[:pass].secret?,
10
+ tainted?: pass.tainted?
11
+ )
13
12
  end
14
13
  end
15
14
 
16
- Cl.new('owners').run(%w(add --password pass))
15
+ Cl.new('owners').run(%w(add --pass pass))
17
16
 
18
17
  # Output:
19
18
  #
20
- # secret? true
21
- # tainted? true
19
+ # {:secret?=>true, :tainted?=>true}
@@ -5,17 +5,15 @@ require 'cl'
5
5
 
6
6
  class Add < Cl::Cmd
7
7
  opt '--to GROUP', see: 'https://docs.io/cli/owners/add'
8
-
9
- def run
10
- p retries
11
- end
12
8
  end
13
9
 
14
10
  Cl.new('owners').run(%w(add --help))
15
11
 
16
- # Usage: see add [options]
12
+ # Output:
13
+ #
14
+ # Usage: owners add [options]
17
15
  #
18
- # Options:
16
+ # Options:
19
17
  #
20
- # --to GROUP type: string, see: https://docs.io/cli/owners/add
21
- # --help Get help on this command
18
+ # --to GROUP type: string, see: https://docs.io/cli/owners/add
19
+ # --help Get help on this command
@@ -1,15 +1,13 @@
1
1
  #!/usr/bin/env ruby
2
2
  $: << File.expand_path('lib')
3
3
 
4
- require 'cl'
5
-
6
4
  class Add < Cl::Cmd
7
5
  opt '--active BOOL', type: :boolean
8
6
  opt '--retries INT', type: :integer
9
7
  opt '--sleep FLOAT', type: :float
10
8
 
11
9
  def run
12
- p active.class, retries.class, sleep.class
10
+ p active: active.class, retries: retries.class, sleep: sleep.class
13
11
  end
14
12
  end
15
13
 
@@ -17,6 +15,4 @@ Cl.new('owners').run(%w(add --active yes --retries 1 --sleep 0.1))
17
15
 
18
16
  # Output:
19
17
  #
20
- # TrueClass
21
- # Integer
22
- # Float
18
+ # {:active=>TrueClass, :retries=>Integer, :sleep=>Float}
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Cast
8
+ class Bool < Cl::Cmd
9
+ arg :bool, type: :bool
10
+
11
+ def run
12
+ p cmd: registry_key, bool: bool
13
+ end
14
+ end
15
+
16
+ class Types < Cl::Cmd
17
+ arg :a, type: :bool
18
+ arg :b, type: :int
19
+ arg :c, type: :float
20
+ arg :d
21
+
22
+ def run
23
+ p cmd: registry_key, a: a, b: b, c: c, d: d
24
+ end
25
+ end
26
+ end
27
+ rb
28
+ -%>
29
+
30
+ <%= run 'Cl.new($0).run(%w(bool on))' %>
31
+
32
+ <%= out '{:cmd=>:bool, :bool=>true}' %>
33
+
34
+ <%= run 'Cl.new($0).run(%w(types true 1 1.2 foo))' %>
35
+
36
+ <%= out '{:cmd=>:types, :a=>true, :b=>1, :c=>1.2, :d=>"foo"}' %>
37
+
38
+ <%= run 'Cl.new($0).run(%w(types true 1 1.2 foo bar))' %>
39
+
40
+ <%= out sq(<<-'str')
41
+ Too many arguments (given: 5, allowed: 4)
42
+
43
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
44
+
45
+ Arguments:
46
+
47
+ a type: bool
48
+ b type: int
49
+ c type: float
50
+ d type: string
51
+
52
+ Options:
53
+
54
+ --help Get help on this command
55
+ str
56
+ %>
57
+
58
+ <%= run 'Cl.new($0).run(%w(types true one 1.2))' %>
59
+
60
+ <%= out sq(<<-'str')
61
+ Wrong argument type (given: "one", expected: int)
62
+
63
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
64
+
65
+ Arguments:
66
+
67
+ a type: bool
68
+ b type: int
69
+ c type: float
70
+ d type: string
71
+
72
+ Options:
73
+
74
+ --help Get help on this command
75
+ str
76
+ %>
77
+
78
+ <%= run 'Cl.new($0).run(%w(types true 1 one))' %>
79
+
80
+ <%= out sq(<<-'str')
81
+ Wrong argument type (given: "one", expected: float)
82
+
83
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
84
+
85
+ Arguments:
86
+
87
+ a type: bool
88
+ b type: int
89
+ c type: float
90
+ d type: string
91
+
92
+ Options:
93
+
94
+ --help Get help on this command
95
+ str
96
+ %>
@@ -0,0 +1,96 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Opts
8
+ class Bool < Cl::Cmd
9
+ arg :bool, type: :bool
10
+
11
+ def run
12
+ p cmd: registry_key, bool: bool
13
+ end
14
+ end
15
+
16
+ class Types < Cl::Cmd
17
+ arg :a, type: :bool
18
+ arg :b, type: :int
19
+ arg :c, type: :float
20
+ arg :d
21
+
22
+ def run
23
+ p cmd: registry_key, a: a, b: b, c: c, d: d
24
+ end
25
+ end
26
+ end
27
+ rb
28
+ -%>
29
+
30
+ <%= run 'Cl.new($0).run(%w(bool on))' %>
31
+
32
+ <%= out '{:cmd=>:bool, :bool=>true}' %>
33
+
34
+ <%= run 'Cl.new($0).run(%w(types true 1 1.2 foo))' %>
35
+
36
+ <%= out '{:cmd=>:types, :a=>true, :b=>1, :c=>1.2, :d=>"foo"}' %>
37
+
38
+ <%= run 'Cl.new($0).run(%w(types true 1 1.2 foo bar))' %>
39
+
40
+ <%= out sq(<<-'str')
41
+ Too many arguments (given: 5, allowed: 4)
42
+
43
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
44
+
45
+ Arguments:
46
+
47
+ a type: bool
48
+ b type: int
49
+ c type: float
50
+ d type: string
51
+
52
+ Options:
53
+
54
+ --help Get help on this command
55
+ str
56
+ %>
57
+
58
+ <%= run 'Cl.new($0).run(%w(types true one 1.2))' %>
59
+
60
+ <%= out sq(<<-'str')
61
+ Wrong argument type (given: "one", expected: int)
62
+
63
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
64
+
65
+ Arguments:
66
+
67
+ a type: bool
68
+ b type: int
69
+ c type: float
70
+ d type: string
71
+
72
+ Options:
73
+
74
+ --help Get help on this command
75
+ str
76
+ %>
77
+
78
+ <%= run 'Cl.new($0).run(%w(types true 1 one))' %>
79
+
80
+ <%= out sq(<<-'str')
81
+ Wrong argument type (given: "one", expected: float)
82
+
83
+ Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
84
+
85
+ Arguments:
86
+
87
+ a type: bool
88
+ b type: int
89
+ c type: float
90
+ d type: string
91
+
92
+ Options:
93
+
94
+ --help Get help on this command
95
+ str
96
+ %>