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
@@ -3,67 +3,57 @@ $: << File.expand_path('lib')
3
3
 
4
4
  require 'cl'
5
5
 
6
- class Bool < Cl::Cmd
7
- arg :bool, type: :bool
6
+ module Cast
7
+ class Bool < Cl::Cmd
8
+ arg :bool, type: :bool
8
9
 
9
- def run
10
- [registry_key, bool: bool]
10
+ def run
11
+ p cmd: registry_key, bool: bool
12
+ end
11
13
  end
12
- end
13
14
 
14
- class Types < Cl::Cmd
15
- arg :a, type: :bool
16
- arg :b, type: :int
17
- arg :c, type: :float
18
- arg :d
15
+ class Types < Cl::Cmd
16
+ arg :a, type: :bool
17
+ arg :b, type: :int
18
+ arg :c, type: :float
19
+ arg :d
19
20
 
20
- def run
21
- [registry_key, a: a, b: b, c: c, d: d]
21
+ def run
22
+ p cmd: registry_key, a: a, b: b, c: c, d: d
23
+ end
22
24
  end
23
25
  end
24
26
 
25
- def output(cmd, args)
26
- args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
27
- puts "Called #{cmd} with #{args}\n\n"
28
- end
29
-
30
- output *Cl.new($0).run(%w(bool on))
27
+ Cl.new($0).run(%w(bool on))
31
28
 
32
29
  # Output:
33
30
  #
34
- # Called bool with bool=true
31
+ # {:cmd=>:bool, :bool=>true}
35
32
 
36
- output *Cl.new($0).run(%w(bool on))
33
+ Cl.new($0).run(%w(types true 1 1.2 foo))
37
34
 
38
35
  # Output:
39
36
  #
40
- # Called bool with bool=true
37
+ # {:cmd=>:types, :a=>true, :b=>1, :c=>1.2, :d=>"foo"}
41
38
 
42
- output *Cl.new($0).run(%w(bool on))
39
+ Cl.new($0).run(%w(types true 1 1.2 foo bar))
43
40
 
44
41
  # Output:
45
42
  #
46
- # Called bool with bool=true
47
-
48
- output *Cl.new($0).run(%w(bool on))
49
-
50
- # Output:
43
+ # Too many arguments (given: 5, allowed: 4)
51
44
  #
52
- # Called bool with bool=true
53
-
54
- output *Cl.new($0).run(%w(types true 1 1.2 foo))
55
-
56
- # Output:
45
+ # Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
57
46
  #
58
- # Called types with a=true b=1 c=1.2 d="foo"
59
-
60
- Cl.new($0).run(%w(types true 1 1.2))
61
-
62
- # Output:
47
+ # Arguments:
63
48
  #
64
- # Too many arguments (given: 5, allowed: 4)
49
+ # a type: bool
50
+ # b type: int
51
+ # c type: float
52
+ # d type: string
53
+ #
54
+ # Options:
65
55
  #
66
- # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
56
+ # --help Get help on this command
67
57
 
68
58
  Cl.new($0).run(%w(types true one 1.2))
69
59
 
@@ -71,7 +61,18 @@ Cl.new($0).run(%w(types true one 1.2))
71
61
  #
72
62
  # Wrong argument type (given: "one", expected: int)
73
63
  #
74
- # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
64
+ # Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
65
+ #
66
+ # Arguments:
67
+ #
68
+ # a type: bool
69
+ # b type: int
70
+ # c type: float
71
+ # d type: string
72
+ #
73
+ # Options:
74
+ #
75
+ # --help Get help on this command
75
76
 
76
77
  Cl.new($0).run(%w(types true 1 one))
77
78
 
@@ -79,4 +80,15 @@ Cl.new($0).run(%w(types true 1 one))
79
80
  #
80
81
  # Wrong argument type (given: "one", expected: float)
81
82
  #
82
- # Usage: cast.rb types [a (bool)] [b (int)] [c (float)] [d]
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
@@ -3,34 +3,92 @@ $: << File.expand_path('lib')
3
3
 
4
4
  require 'cl'
5
5
 
6
- class Opts < Cl::Cmd
7
- opt '-p', '--path PATH'
8
- opt '-v', '--verbose'
6
+ module Opts
7
+ class Bool < Cl::Cmd
8
+ arg :bool, type: :bool
9
9
 
10
- def run
11
- [registry_key, args, opts]
10
+ def run
11
+ p cmd: registry_key, bool: bool
12
+ end
12
13
  end
13
- end
14
14
 
15
- def output(cmd, args, opts)
16
- puts "Called #{cmd} with args=#{args} opts=#{opts}\n\n"
15
+ class Types < Cl::Cmd
16
+ arg :a, type: :bool
17
+ arg :b, type: :int
18
+ arg :c, type: :float
19
+ arg :d
20
+
21
+ def run
22
+ p cmd: registry_key, a: a, b: b, c: c, d: d
23
+ end
24
+ end
17
25
  end
18
26
 
19
- output *Cl.new($0).run(%w(opts -p path -v))
27
+ Cl.new($0).run(%w(bool on))
20
28
 
21
29
  # Output:
22
30
  #
23
- # Called cast with args=[] opts={:path=>"path", :verbose=>true}
31
+ # {:cmd=>:bool, :bool=>true}
24
32
 
25
- output *Cl.new($0).run(%w(opts --path path --verbose))
33
+ Cl.new($0).run(%w(types true 1 1.2 foo))
26
34
 
27
35
  # Output:
28
36
  #
29
- # Called cast with args=[] opts={:path=>"path", :verbose=>true}
37
+ # {:cmd=>:types, :a=>true, :b=>1, :c=>1.2, :d=>"foo"}
30
38
 
31
- output *Cl.new($0).run(%w(opts one -p path two -v three))
39
+ Cl.new($0).run(%w(types true 1 1.2 foo bar))
32
40
 
33
41
  # Output:
34
42
  #
35
- # Called cast with args=["one", "two", "three"] opts={:path=>"path", :verbose=>true}
43
+ # Too many arguments (given: 5, allowed: 4)
44
+ #
45
+ # Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
46
+ #
47
+ # Arguments:
48
+ #
49
+ # a type: bool
50
+ # b type: int
51
+ # c type: float
52
+ # d type: string
53
+ #
54
+ # Options:
55
+ #
56
+ # --help Get help on this command
57
+
58
+ Cl.new($0).run(%w(types true one 1.2))
36
59
 
60
+ # Output:
61
+ #
62
+ # Wrong argument type (given: "one", expected: int)
63
+ #
64
+ # Usage: bin/examples types [a:bool] [b:int] [c:float] [d] [options]
65
+ #
66
+ # Arguments:
67
+ #
68
+ # a type: bool
69
+ # b type: int
70
+ # c type: float
71
+ # d type: string
72
+ #
73
+ # Options:
74
+ #
75
+ # --help Get help on this command
76
+
77
+ Cl.new($0).run(%w(types true 1 one))
78
+
79
+ # Output:
80
+ #
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
@@ -8,39 +8,53 @@ class Required < Cl::Cmd
8
8
  arg :two
9
9
 
10
10
  def run
11
- [registry_key, one: one, two: two]
11
+ p cmd: registry_key, one: one, two: two
12
12
  end
13
13
  end
14
14
 
15
- def output(cmd, args)
16
- args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
17
- puts "Called #{cmd} with #{args}\n\n"
18
- end
19
-
20
- output *Cl.new($0).run(%w(required one two))
15
+ Cl.new($0).run(%w(required one two))
21
16
 
22
17
  # Output:
23
18
  #
24
- # Called required with one="one" two="two"
19
+ # {:cmd=>:required, :one=>"one", :two=>"two"}
25
20
 
26
- output *Cl.new($0).run(%w(required one))
21
+ Cl.new($0).run(%w(required one))
27
22
 
28
23
  # Output:
29
24
  #
30
- # Called required with one="one" two=nil
25
+ # {:cmd=>:required, :one=>"one", :two=>nil}
31
26
 
32
- output *Cl.new($0).run(%w(required))
27
+ Cl.new($0).run(%w(required))
33
28
 
34
29
  # Output:
35
30
  #
36
31
  # Missing arguments (given: 0, required: 1)
37
32
  #
38
- # Usage: args.rb required one [two]
33
+ # Usage: bin/examples required one [two] [options]
34
+ #
35
+ # Arguments:
36
+ #
37
+ # one type: string, required: true
38
+ # two type: string
39
+ #
40
+ # Options:
41
+ #
42
+ # --help Get help on this command
39
43
 
40
- output *Cl.new($0).run(%w(required one two three))
44
+ Cl.new($0).run(%w(required one two three))
41
45
 
42
46
  # Output:
43
47
  #
44
48
  # Too many arguments (given: 3, allowed: 2)
45
49
  #
46
- # Usage: args.rb required one [two]
50
+ # Usage: bin/examples required one [two] [options]
51
+ #
52
+ # Arguments:
53
+ #
54
+ # one type: string, required: true
55
+ # two type: string
56
+ #
57
+ # Options:
58
+ #
59
+ # --help Get help on this command
60
+
@@ -3,59 +3,56 @@ $: << File.expand_path('lib')
3
3
 
4
4
  require 'cl'
5
5
 
6
- class SplatLeft < Cl::Cmd
7
- register 'splat:left'
6
+ module Splat
7
+ class Left < Cl::Cmd
8
+ register :left
8
9
 
9
- arg :one, type: :array
10
- args :two, :three
10
+ arg :one, type: :array, splat: true
11
+ args :two, :three
11
12
 
12
- def run
13
- [registry_key, one: one, two: two, three: three]
13
+ def run
14
+ p cmd: registry_key, one: one, two: two, three: three
15
+ end
14
16
  end
15
- end
16
17
 
17
- class SplatMiddle < Cl::Cmd
18
- register 'splat:middle'
18
+ class Middle < Cl::Cmd
19
+ register :middle
19
20
 
20
- arg :one
21
- arg :two, type: :array
22
- arg :three
21
+ arg :one
22
+ arg :two, type: :array, splat: true
23
+ arg :three
23
24
 
24
- def run
25
- [registry_key, one: one, two: two, three: three]
25
+ def run
26
+ p cmd: registry_key, one: one, two: two, three: three
27
+ end
26
28
  end
27
- end
28
29
 
29
- class SplatRight < Cl::Cmd
30
- register 'splat:right'
30
+ class Right < Cl::Cmd
31
+ register :right
31
32
 
32
- args :one, :two
33
- arg :three, type: :array
33
+ args :one, :two
34
+ arg :three, type: :array, splat: true
34
35
 
35
- def run
36
- [registry_key, one: one, two: two, three: three]
36
+ def run
37
+ p cmd: registry_key, one: one, two: two, three: three
38
+ end
37
39
  end
38
40
  end
39
41
 
40
- def output(cmd, args)
41
- args = args.map { |key, value| "#{key}=#{value.inspect}" }.join(' ')
42
- puts "Called #{cmd} with #{args}\n\n"
43
- end
44
-
45
- output *Cl.new($0).run(%w(splat left foo bar baz buz))
42
+ Cl.new('splat').run(%w(left foo bar baz buz))
46
43
 
47
44
  # Output:
48
45
  #
49
- # Called splat:left with one=["foo", "bar"] two="baz" three="buz"
46
+ # {:cmd=>:left, :one=>["foo", "bar"], :two=>"baz", :three=>"buz"}
50
47
 
51
- output *Cl.new($0).run(%w(splat middle foo bar baz buz))
48
+ Cl.new('splat').run(%w(middle foo bar baz buz))
52
49
 
53
50
  # Output:
54
51
  #
55
- # Called splat:middle with one="foo" two=["bar", "baz"] three="buz"
52
+ # {:cmd=>:middle, :one=>"foo", :two=>["bar", "baz"], :three=>"buz"}
56
53
 
57
- output *Cl.new($0).run(%w(splat right foo bar baz buz))
54
+ Cl.new('splat').run(%w(right foo bar baz buz))
58
55
 
59
56
  # Output:
60
57
  #
61
- # Called splat:middle with one="foo" two="bar" three=["baz", "buz"]
58
+ # {:cmd=>:right, :one=>"foo", :two=>"bar", :three=>["baz", "buz"]}
@@ -14,26 +14,23 @@ module Gem
14
14
  opt '-q', '--quiet', 'Silence output'
15
15
 
16
16
  def run
17
- [registry_key, args, opts]
17
+ p cmd: registry_key, args: args, opts: opts
18
18
  end
19
19
  end
20
20
 
21
21
  class Bump < Cl::Cmd
22
- defaults commit: true
23
-
24
22
  opt '-v', '--version VERSION', 'The version to bump to [1.1.1|major|minor|patch|pre|rc|release]'
25
23
  opt '--[no-]commit', 'Bump the version, but do not commit'
26
24
 
27
25
  def run
28
- [registry_key, args, opts]
26
+ p cmd: registry_key, args: args, opts: opts
29
27
  end
30
28
  end
31
29
  end
32
30
  end
33
31
  end
34
32
 
35
- Cl.new($0).run(%w(help))
36
- puts
33
+ Cl.new('gem').run(%w(help))
37
34
 
38
35
  # Output:
39
36
  #
@@ -42,13 +39,12 @@ puts
42
39
  # gem release [gemspec] [options]
43
40
  # gem bump [options]
44
41
 
45
- Cl.new($0).run(%w(help release))
46
- puts
47
42
 
43
+ Cl.new('gem').run(%w(help release))
48
44
  # or:
49
45
  #
50
- # Cl.new($0).run(%w(release --help)))
51
- # Cl.new($0).run(%w(release -h)))
46
+ # Cl.new('gem').run(%w(release --help)))
47
+ # Cl.new('gem').run(%w(release -h)))
52
48
  #
53
49
  # Output:
54
50
  #
@@ -56,22 +52,21 @@ puts
56
52
  #
57
53
  # Arguments:
58
54
  #
59
- # gemspec
55
+ # gemspec type: string
60
56
  #
61
57
  # Options:
62
58
  #
63
- # -h --host HOST Push to a compatible host other than rubygems.org
64
- # -k --key KEY Rubygems API key to use
65
- # -q --quiet Silence output
66
- # --help Get help on this command
59
+ # -h --host HOST Push to a compatible host other than rubygems.org (type: string)
60
+ # -k --key KEY Rubygems API key to use (type: string)
61
+ # -q --[no-]quiet Silence output
62
+ # --help Get help on this command
67
63
 
68
- Cl.new($0).run(%w(help release))
69
- puts
70
64
 
65
+ Cl.new('gem').run(%w(help bump))
71
66
  # or:
72
67
  #
73
- # Cl.run($0, %w(release --help))
74
- # Cl.run($0, %w(release -h))
68
+ # Cl.new('gem').run(%w(bump --help)))
69
+ # Cl.new('gem').run(%w(bump -h)))
75
70
  #
76
71
  # Output:
77
72
  #
@@ -79,26 +74,20 @@ puts
79
74
  #
80
75
  # Options:
81
76
  #
82
- # -v --version VERSION The version to bump to [1.1.1|major|minor|patch|pre|rc|release]
83
- # --no-commit Bump the version, but do not commit
84
- # -h --help Get help on this command
77
+ # -v --version VERSION The version to bump to [1.1.1|major|minor|patch|pre|rc|release] (type: string)
78
+ # --[no-]commit Bump the version, but do not commit
79
+ # --help Get help on this command
85
80
 
86
- cmds = [
87
- Cl.new($0).run(%w(bump -v 1.1.1)),
88
- Cl.new($0).run(%w(release foo.gemspec -h host -k key -q))
89
- ]
90
81
 
91
- puts "Commands run:\n\n"
92
- puts cmds.map { |cmd, args, opts| " cmd #{cmd} has run with:\n\n args=#{args}\n opts=#{opts}\n\n" }
82
+ Cl.new('gem').run(%w(bump -v 1.1.1))
93
83
 
94
- # Commands run:
95
- #
96
- # cmd bump has run with:
97
- #
98
- # args=[]
99
- # opts={:version=>"1.1.1"}
84
+ # Output:
100
85
  #
101
- # cmd release has run with:
86
+ # {:cmd=>:bump, :args=>[], :opts=>{:version=>"1.1.1"}}
87
+
88
+
89
+ Cl.new('gem').run(%w(release foo.gemspec -h host -k key -q))
90
+
91
+ # Output:
102
92
  #
103
- # args=["foo.gemspec"]
104
- # opts={:host=>"host", :key=>"key", :quiet=>true}
93
+ # {:cmd=>:release, :args=>["foo.gemspec"], :opts=>{:host=>"host", :key=>"key", :quiet=>true}}