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
@@ -12,7 +12,9 @@ module Heroku
12
12
 
13
13
  opt '-o', '--org ORG'
14
14
 
15
- def run; [registry_key, args, opts] end
15
+ def run
16
+ p cmd: registry_key, args: args, opts: opts
17
+ end
16
18
  end
17
19
 
18
20
  class List < Cl::Cmd
@@ -20,30 +22,27 @@ module Heroku
20
22
 
21
23
  opt '-a', '--app APP'
22
24
 
23
- def run; [registry_key, args, opts] end
25
+ def run
26
+ p cmd: registry_key, args: args, opts: opts
27
+ end
24
28
  end
25
29
  end
26
30
  end
27
31
 
28
- def output(cmd, args, opts)
29
- puts "Called #{cmd} with args=#{args} opts=#{opts}\n\n"
30
- end
31
-
32
- output *Cl.new($0).run(%w(apps:create name -o org))
33
-
34
- # Output:
32
+ Cl.new('heroku').run(%w(apps:create name -o org))
33
+ # or:
35
34
  #
36
- # Called apps:create with args=["name"] opts={:org=>"org"}
37
-
38
- output *Cl.new($0).run(%w(apps create name -o org))
35
+ # Cl.new('heroku').run(%w(apps create name -o org))
39
36
 
40
37
  # Output:
41
38
  #
42
- # Called apps:create with args=["name"] opts={:org=>"org"}
39
+ # {:cmd=>:"apps:create", :args=>["name"], :opts=>{:org=>"org"}}
43
40
 
44
- output *Cl.new($0).run(%w(apps:info -a app))
41
+ Cl.new('heroku').run(%w(apps:info -a app))
42
+ # or:
43
+ #
44
+ # Cl.new('heroku').run(%w(apps info -a app))
45
45
 
46
46
  # Output:
47
47
  #
48
- # Called apps:create with args=["app"] opts={}
49
-
48
+ # {:cmd=>:"apps:info", :args=>[], :opts=>{:app=>"app"}}
@@ -10,7 +10,9 @@ module Rakeish
10
10
 
11
11
  arg :name
12
12
 
13
- def run; [registry_key, args, opts] end
13
+ def run
14
+ p cmd: registry_key, args: args, opts: opts
15
+ end
14
16
  end
15
17
 
16
18
  class Drop < Cl::Cmd
@@ -20,7 +22,9 @@ module Rakeish
20
22
 
21
23
  opt '-f', '--force'
22
24
 
23
- def run; [registry_key, args, opts] end
25
+ def run
26
+ p cmd: registry_key, args: args, opts: opts
27
+ end
24
28
  end
25
29
 
26
30
  class Migrate < Cl::Cmd
@@ -30,23 +34,17 @@ module Rakeish
30
34
 
31
35
  opt '-v', '--version VERSION'
32
36
 
33
- def run; [registry_key, args, opts] end
37
+ def run
38
+ p cmd: registry_key, args: args, opts: opts
39
+ end
34
40
  end
35
41
  end
36
42
  end
37
43
 
38
- def output(result)
39
- result.each do |cmd, args, opts|
40
- puts "Called #{cmd} with args=#{args} opts=#{opts}"
41
- end
42
- puts
43
- end
44
-
45
- argv = %w(db:drop production -f db:create db:migrate production -v 1)
46
- output Cl.new($0, runner: :multi).run(argv)
44
+ Cl.new('rake', runner: :multi).run(%w(db:drop production -f db:create db:migrate production -v 1))
47
45
 
48
46
  # Output:
49
47
  #
50
- # Called db:drop with args=["production"] opts={:force=>true}
51
- # Called db:create with args=[] opts={}
52
- # Called db:migrate with args=["production"] opts={:version=>"1"}
48
+ # {:cmd=>:"db:drop", :args=>["production"], :opts=>{:force=>true}}
49
+ # {:cmd=>:"db:create", :args=>[], :opts=>{}}
50
+ # {:cmd=>:"db:migrate", :args=>["production"], :opts=>{:version=>"1"}}
@@ -8,18 +8,19 @@ class Base < Cl::Cmd
8
8
  end
9
9
 
10
10
  class Add < Base
11
+ def run
12
+ puts 'Success'
13
+ end
11
14
  end
12
15
 
13
- Cl.new('owners').help
16
+ Cl.new('owners').run(%w(add))
14
17
 
15
18
  # Output:
16
19
  #
17
- # Type "owners help COMMAND [SUBCOMMAND]" for more details:
18
- #
19
- # owners add [options]
20
+ # Success
20
21
 
21
22
  Cl.new('owners').run(%w(base))
22
23
 
23
- # Error output:
24
+ # Output:
24
25
  #
25
26
  # Unknown command: base
@@ -7,16 +7,13 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', alias: :group
8
8
 
9
9
  def run
10
- p opts, to, to?, group, group?
10
+ # p opts: opts, to: to, to?: to?, group: group, group?: group?
11
+ p opts: opts, to: to, to?: to?
11
12
  end
12
13
  end
13
14
 
14
- Cl.new('owners').run(%w(add --to one))
15
+ Cl.new('owners').run(%w(add --group one))
15
16
 
16
17
  # Output:
17
18
  #
18
- # {"to" => "one"}
19
- # "one"
20
- # true
21
- # "one"
22
- # true
19
+ # {:opts=>{:to=>"one", :group=>"one"}, :to=>"one", :to?=>true}
@@ -7,10 +7,12 @@ class Add < Cl::Cmd
7
7
  arg :owner
8
8
 
9
9
  def run
10
- p owner
10
+ p owner: owner
11
11
  end
12
12
  end
13
13
 
14
14
  Cl.new('owners').run(%w(add one))
15
15
 
16
- # => "one"
16
+ # Output:
17
+ #
18
+ # {:owner=>"one"}
@@ -7,10 +7,12 @@ class Add < Cl::Cmd
7
7
  arg :owners, type: :array, sep: ','
8
8
 
9
9
  def run
10
- p owners
10
+ p owners: owners
11
11
  end
12
12
  end
13
13
 
14
14
  Cl.new('owners').run(%w(add one,two))
15
15
 
16
- # => ["one", "two"]
16
+ # Output:
17
+ #
18
+ # {:owners=>["one", "two"]}
@@ -15,4 +15,6 @@ end
15
15
 
16
16
  Cl.new('owners').run(%w(cmd 1 2.1 yes))
17
17
 
18
- # => [Integer, Float, TrueClass]
18
+ # Output:
19
+ #
20
+ # [Integer, Float, TrueClass]
@@ -34,10 +34,19 @@ class Rgt < Cl::Cmd
34
34
  end
35
35
 
36
36
  Cl.new('splat').run(%w(lft 1 2 3 4 5))
37
+
38
+ # Output:
39
+ #
40
+ # [["1", "2", "3"], "4", "5"]
41
+
37
42
  Cl.new('splat').run(%w(mid 1 2 3 4 5))
43
+
44
+ # Output:
45
+ #
46
+ # ["1", ["2", "3", "4"], "5"]
47
+
38
48
  Cl.new('splat').run(%w(rgt 1 2 3 4 5))
39
49
 
40
- # =>
41
- # [["1", "2", "3"], "4", "5"]
42
- # ["1", ["2", "3", "4"], "5"]
43
- # ["1", "2", ["3", "4", "5"]]
50
+ # Output:
51
+ #
52
+ # ["1", "2", ["3", "4", "5"]]
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', default: 'default'
8
8
 
9
9
  def run
10
- p to
10
+ p to: to
11
11
  end
12
12
  end
13
13
 
@@ -15,4 +15,4 @@ Cl.new('owners').run(%w(add))
15
15
 
16
16
  # Output:
17
17
  #
18
- # "default"
18
+ # {:to=>"default"}
@@ -4,11 +4,10 @@ $: << File.expand_path('lib')
4
4
  require 'cl'
5
5
 
6
6
  class Add < Cl::Cmd
7
- opt '--to GROUP'
8
- opt '--target GROUP', deprecated: 'Deprecated: --target'
7
+ opt '--target GROUP', deprecated: 'Deprecated.'
9
8
 
10
9
  def run
11
- p to, deprecated_opts
10
+ p target: target, deprecations: deprecations
12
11
  end
13
12
  end
14
13
 
@@ -16,6 +15,4 @@ Cl.new('owners').run(%w(add --target one))
16
15
 
17
16
  # Output:
18
17
  #
19
- # "one"
20
- # {:target=>'Deprecated: --target'}
21
-
18
+ # {:target=>"one", :deprecations=>{:target=>"Deprecated."}}
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', alias: :target, deprecated: :target
8
8
 
9
9
  def run
10
- p to, deprecated_opts
10
+ p to: to, deprecations: deprecations
11
11
  end
12
12
  end
13
13
 
@@ -15,6 +15,4 @@ Cl.new('owners').run(%w(add --target one))
15
15
 
16
16
  # Output:
17
17
  #
18
- # "one"
19
- # {:target=>:to}
20
-
18
+ # {:to=>"one", :deprecations=>{:target=>:to}}
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', downcase: true
8
8
 
9
9
  def run
10
- p to
10
+ p to: to
11
11
  end
12
12
  end
13
13
 
@@ -15,4 +15,4 @@ Cl.new('owners').run(%w(add --to ONE))
15
15
 
16
16
  # Output:
17
17
  #
18
- # "one"
18
+ # {:to=>"one"}
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', enum: %w(one two)
8
8
 
9
9
  def run
10
- p to
10
+ p to: to
11
11
  end
12
12
  end
13
13
 
@@ -15,12 +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 --to unknown))
21
21
 
22
- # Unknown value: to=unknown (known values: one, two)
22
+ # Output:
23
+ #
24
+ # Unknown value: to=unknown (known values: one, two)
25
+ #
26
+ # Usage: owners add [options]
23
27
  #
24
- # Usage: enum add [options]
28
+ # Options:
25
29
  #
26
- # Options: ...
30
+ # --to GROUP type: string, known values: one, two
31
+ # --help Get help on this command
@@ -9,9 +9,11 @@ end
9
9
 
10
10
  Cl.new('owners').run(%w(add --help))
11
11
 
12
- # Usage: example add [options]
12
+ # Output:
13
13
  #
14
- # Options:
14
+ # Usage: owners add [options]
15
15
  #
16
- # --to GROUP type: string, e.g.: group-one
17
- # --help Get help on this command
16
+ # Options:
17
+ #
18
+ # --to GROUP type: string, e.g.: group-one
19
+ # --help Get help on this command
@@ -7,7 +7,7 @@ class Add < Cl::Cmd
7
7
  opt '--to GROUP', format: /^\w+$/
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(['add', '--to', 'does not match!'])
21
21
 
22
- # Invalid format: to (format: /^\w+$/)
22
+ # Output:
23
+ #
24
+ # Invalid format: to (format: /^\w+$/)
23
25
  #
24
- # Usage: format add [options]
26
+ # Usage: owners add [options]
25
27
  #
26
- # Options:
28
+ # Options:
27
29
  #
28
- # --to GROUP type: string, format: /^\w+$/
29
- # --help Get help on this command
30
+ # --to GROUP type: string, format: /^\w+$/
31
+ # --help Get help on this command
@@ -3,6 +3,8 @@ $: << File.expand_path('lib')
3
3
 
4
4
  require 'cl'
5
5
 
6
+ require 'cl'
7
+
6
8
  class Add < Cl::Cmd
7
9
  opt '--to GROUP'
8
10
  opt '--hidden', internal: true
@@ -10,9 +12,11 @@ end
10
12
 
11
13
  Cl.new('owners').run(%w(add --help))
12
14
 
13
- # Usage: example add [options]
15
+ # Output:
16
+ #
17
+ # Usage: owners add [options]
14
18
  #
15
- # Options:
19
+ # Options:
16
20
  #
17
- # --to GROUP type: string, e.g.: group-one
18
- # --help Get help on this command
21
+ # --to GROUP type: string
22
+ # --help Get help on this command
@@ -12,16 +12,31 @@ class Add < Cl::Cmd
12
12
  end
13
13
 
14
14
  Cl.new('owners').run(%w(add --notifications))
15
- # => true
15
+
16
+ # Output:
17
+ #
18
+ # true
16
19
 
17
20
  Cl.new('owners').run(%w(add --no_notifications))
18
- # => false
21
+
22
+ # Output:
23
+ #
24
+ # false
19
25
 
20
26
  Cl.new('owners').run(%w(add --no-notifications))
21
- # => false
27
+
28
+ # Output:
29
+ #
30
+ # false
22
31
 
23
32
  Cl.new('owners').run(%w(add --skip_notifications))
24
- # => false
33
+
34
+ # Output:
35
+ #
36
+ # false
25
37
 
26
38
  Cl.new('owners').run(%w(add --skip-notifications))
27
- # => false
39
+
40
+ # Output:
41
+ #
42
+ # false
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ require 'cl'
5
+
6
+ class Add < Cl::Cmd
7
+ opt '--to GROUP', note: 'needs to be a group'
8
+ end
9
+
10
+ Cl.new('owners').run(%w(add --help))
11
+
12
+ # Output:
13
+ #
14
+ # Usage: owners add [options]
15
+ #
16
+ # Options:
17
+ #
18
+ # --to GROUP type: string, note: needs to be a group
19
+ # --help Get help on this command