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
@@ -0,0 +1,61 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Required < Cl::Cmd
8
+ arg :one, required: true
9
+ arg :two
10
+
11
+ def run
12
+ p cmd: registry_key, one: one, two: two
13
+ end
14
+ end
15
+ rb
16
+ -%>
17
+
18
+ <%= run 'Cl.new($0).run(%w(required one two))' %>
19
+
20
+ <%= out '{:cmd=>:required, :one=>"one", :two=>"two"}' %>
21
+
22
+ <%= run 'Cl.new($0).run(%w(required one))' %>
23
+
24
+ <%= out '{:cmd=>:required, :one=>"one", :two=>nil}' %>
25
+
26
+ <%= run 'Cl.new($0).run(%w(required))' %>
27
+
28
+ <%= out sq(<<-'str')
29
+ Missing arguments (given: 0, required: 1)
30
+
31
+ Usage: bin/examples required one [two] [options]
32
+
33
+ Arguments:
34
+
35
+ one type: string, required: true
36
+ two type: string
37
+
38
+ Options:
39
+
40
+ --help Get help on this command
41
+ str
42
+ %>
43
+
44
+ <%= run 'Cl.new($0).run(%w(required one two three))' %>
45
+
46
+ <%= out sq(<<-'str')
47
+ Too many arguments (given: 3, allowed: 2)
48
+
49
+ Usage: bin/examples required one [two] [options]
50
+
51
+ Arguments:
52
+
53
+ one type: string, required: true
54
+ two type: string
55
+
56
+ Options:
57
+
58
+ --help Get help on this command
59
+ str
60
+ %>
61
+
@@ -0,0 +1,55 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Splat
8
+ class Left < Cl::Cmd
9
+ register :left
10
+
11
+ arg :one, type: :array, splat: true
12
+ args :two, :three
13
+
14
+ def run
15
+ p cmd: registry_key, one: one, two: two, three: three
16
+ end
17
+ end
18
+
19
+ class Middle < Cl::Cmd
20
+ register :middle
21
+
22
+ arg :one
23
+ arg :two, type: :array, splat: true
24
+ arg :three
25
+
26
+ def run
27
+ p cmd: registry_key, one: one, two: two, three: three
28
+ end
29
+ end
30
+
31
+ class Right < Cl::Cmd
32
+ register :right
33
+
34
+ args :one, :two
35
+ arg :three, type: :array, splat: true
36
+
37
+ def run
38
+ p cmd: registry_key, one: one, two: two, three: three
39
+ end
40
+ end
41
+ end
42
+ rb
43
+ -%>
44
+
45
+ <%= run "Cl.new('splat').run(%w(left foo bar baz buz))" %>
46
+
47
+ <%= out '{:cmd=>:left, :one=>["foo", "bar"], :two=>"baz", :three=>"buz"}' %>
48
+
49
+ <%= run "Cl.new('splat').run(%w(middle foo bar baz buz))" %>
50
+
51
+ <%= out '{:cmd=>:middle, :one=>"foo", :two=>["bar", "baz"], :three=>"buz"}' %>
52
+
53
+ <%= run "Cl.new('splat').run(%w(right foo bar baz buz))" %>
54
+
55
+ <%= out '{:cmd=>:right, :one=>"foo", :two=>"bar", :three=>["baz", "buz"]}' %>
@@ -0,0 +1,95 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Gem
8
+ module Release
9
+ module Cmds
10
+ class Release < Cl::Cmd
11
+ arg :gemspec
12
+
13
+ opt '-h', '--host HOST', 'Push to a compatible host other than rubygems.org'
14
+ opt '-k', '--key KEY', 'Rubygems API key to use'
15
+ opt '-q', '--quiet', 'Silence output'
16
+
17
+ def run
18
+ p cmd: registry_key, args: args, opts: opts
19
+ end
20
+ end
21
+
22
+ class Bump < Cl::Cmd
23
+ opt '-v', '--version VERSION', 'The version to bump to [1.1.1|major|minor|patch|pre|rc|release]'
24
+ opt '--[no-]commit', 'Bump the version, but do not commit'
25
+
26
+ def run
27
+ p cmd: registry_key, args: args, opts: opts
28
+ end
29
+ end
30
+ end
31
+ end
32
+ end
33
+ rb
34
+ -%>
35
+
36
+ <%= run "Cl.new('gem').run(%w(help))" %>
37
+
38
+ <%= out sq(<<-'str')
39
+ Type "gem help COMMAND [SUBCOMMAND]" for more details:
40
+
41
+ gem release [gemspec] [options]
42
+ gem bump [options]
43
+ str
44
+ %>
45
+
46
+
47
+ <%= run "Cl.new('gem').run(%w(help release))" %>
48
+ # or:
49
+ #
50
+ # Cl.new('gem').run(%w(release --help)))
51
+ # Cl.new('gem').run(%w(release -h)))
52
+ #
53
+ <%= out sq(<<-'str')
54
+ Usage: gem release [gemspec] [options]
55
+
56
+ Arguments:
57
+
58
+ gemspec type: string
59
+
60
+ Options:
61
+
62
+ -h --host HOST Push to a compatible host other than rubygems.org (type: string)
63
+ -k --key KEY Rubygems API key to use (type: string)
64
+ -q --[no-]quiet Silence output
65
+ --help Get help on this command
66
+ str
67
+ %>
68
+
69
+
70
+ <%= run "Cl.new('gem').run(%w(help bump))" %>
71
+ # or:
72
+ #
73
+ # Cl.new('gem').run(%w(bump --help)))
74
+ # Cl.new('gem').run(%w(bump -h)))
75
+ #
76
+ <%= out sq(<<-'str')
77
+ Usage: gem bump [options]
78
+
79
+ Options:
80
+
81
+ -v --version VERSION The version to bump to [1.1.1|major|minor|patch|pre|rc|release] (type: string)
82
+ --[no-]commit Bump the version, but do not commit
83
+ --help Get help on this command
84
+ str
85
+ %>
86
+
87
+
88
+ <%= run "Cl.new('gem').run(%w(bump -v 1.1.1))" %>
89
+
90
+ <%= out '{:cmd=>:bump, :args=>[], :opts=>{:version=>"1.1.1"}}' %>
91
+
92
+
93
+ <%= run "Cl.new('gem').run(%w(release foo.gemspec -h host -k key -q))" %>
94
+
95
+ <%= out '{:cmd=>:release, :args=>["foo.gemspec"], :opts=>{:host=>"host", :key=>"key", :quiet=>true}}' %>
@@ -0,0 +1,47 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Heroku
8
+ module Apps
9
+ class Create < Cl::Cmd
10
+ register 'apps:create'
11
+
12
+ arg :name, required: true
13
+
14
+ opt '-o', '--org ORG'
15
+
16
+ def run
17
+ p cmd: registry_key, args: args, opts: opts
18
+ end
19
+ end
20
+
21
+ class List < Cl::Cmd
22
+ register 'apps:info'
23
+
24
+ opt '-a', '--app APP'
25
+
26
+ def run
27
+ p cmd: registry_key, args: args, opts: opts
28
+ end
29
+ end
30
+ end
31
+ end
32
+ rb
33
+ -%>
34
+
35
+ <%= run "Cl.new('heroku').run(%w(apps:create name -o org))" %>
36
+ # or:
37
+ #
38
+ # Cl.new('heroku').run(%w(apps create name -o org))
39
+
40
+ <%= out '{:cmd=>:"apps:create", :args=>["name"], :opts=>{:org=>"org"}}' %>
41
+
42
+ <%= run "Cl.new('heroku').run(%w(apps:info -a app))" %>
43
+ # or:
44
+ #
45
+ # Cl.new('heroku').run(%w(apps info -a app))
46
+
47
+ <%= out '{:cmd=>:"apps:info", :args=>[], :opts=>{:app=>"app"}}' %>
@@ -0,0 +1,54 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ module Rakeish
8
+ module Db
9
+ class Create < Cl::Cmd
10
+ register 'db:create'
11
+
12
+ arg :name
13
+
14
+ def run
15
+ p cmd: registry_key, args: args, opts: opts
16
+ end
17
+ end
18
+
19
+ class Drop < Cl::Cmd
20
+ register 'db:drop'
21
+
22
+ arg :name
23
+
24
+ opt '-f', '--force'
25
+
26
+ def run
27
+ p cmd: registry_key, args: args, opts: opts
28
+ end
29
+ end
30
+
31
+ class Migrate < Cl::Cmd
32
+ register 'db:migrate'
33
+
34
+ arg :name
35
+
36
+ opt '-v', '--version VERSION'
37
+
38
+ def run
39
+ p cmd: registry_key, args: args, opts: opts
40
+ end
41
+ end
42
+ end
43
+ end
44
+ rb
45
+ -%>
46
+
47
+ <%= run "Cl.new('rake', runner: :multi).run(%w(db:drop production -f db:create db:migrate production -v 1))" %>
48
+
49
+ <%= out sq(<<-'str')
50
+ {:cmd=>:"db:drop", :args=>["production"], :opts=>{:force=>true}}
51
+ {:cmd=>:"db:create", :args=>[], :opts=>{}}
52
+ {:cmd=>:"db:migrate", :args=>["production"], :opts=>{:version=>"1"}}
53
+ str
54
+ %>
@@ -0,0 +1,25 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ require 'cl'
5
+
6
+ <%= run sq(<<-'rb')
7
+ class Base < Cl::Cmd
8
+ abstract
9
+ end
10
+
11
+ class Add < Base
12
+ def run
13
+ puts 'Success'
14
+ end
15
+ end
16
+ rb
17
+ -%>
18
+
19
+ <%= run "Cl.new('owners').run(%w(add))" %>
20
+
21
+ <%= out 'Success' %>
22
+
23
+ <%= run "Cl.new('owners').run(%w(base))" %>
24
+
25
+ <%= out 'Unknown command: base' %>
@@ -0,0 +1,20 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Add < Cl::Cmd
8
+ opt '--to GROUP', alias: :group
9
+
10
+ def run
11
+ # p opts: opts, to: to, to?: to?, group: group, group?: group?
12
+ p opts: opts, to: to, to?: to?
13
+ end
14
+ end
15
+ rb
16
+ -%>
17
+
18
+ <%= run "Cl.new('owners').run(%w(add --group one))" %>
19
+
20
+ <%= out '{:opts=>{:to=>"one", :group=>"one"}, :to=>"one", :to?=>true}' %>
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Add < Cl::Cmd
8
+ arg :owner
9
+
10
+ def run
11
+ p owner: owner
12
+ end
13
+ end
14
+ rb
15
+ -%>
16
+
17
+ <%= run "Cl.new('owners').run(%w(add one))" %>
18
+
19
+ <%= out '{:owner=>"one"}' %>
@@ -0,0 +1,19 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Add < Cl::Cmd
8
+ arg :owners, type: :array, sep: ','
9
+
10
+ def run
11
+ p owners: owners
12
+ end
13
+ end
14
+ rb
15
+ -%>
16
+
17
+ <%= run "Cl.new('owners').run(%w(add one,two))" %>
18
+
19
+ <%= out '{:owners=>["one", "two"]}' %>
@@ -0,0 +1,21 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Cmd < Cl::Cmd
8
+ arg :one, type: :integer
9
+ arg :two, type: :float
10
+ arg :three, type: :boolean
11
+
12
+ def run
13
+ p [one.class, two.class, three.class]
14
+ end
15
+ end
16
+ rb
17
+ -%>
18
+
19
+ <%= run "Cl.new('owners').run(%w(cmd 1 2.1 yes))" %>
20
+
21
+ <%= out "[#{RUBY_VERSION < '2.4' ? 'Fixnum' : 'Integer'}, Float, TrueClass]" %>
@@ -0,0 +1,49 @@
1
+ #!/usr/bin/env ruby
2
+ $: << File.expand_path('lib')
3
+
4
+ <%= run sq(<<-'rb')
5
+ require 'cl'
6
+
7
+ class Lft < Cl::Cmd
8
+ arg :a, type: :array, splat: true
9
+ arg :b
10
+ arg :c
11
+
12
+ def run
13
+ p [a, b, c]
14
+ end
15
+ end
16
+
17
+ class Mid < Cl::Cmd
18
+ arg :a
19
+ arg :b, type: :array, splat: true
20
+ arg :c
21
+
22
+ def run
23
+ p [a, b, c]
24
+ end
25
+ end
26
+
27
+ class Rgt < Cl::Cmd
28
+ arg :a
29
+ arg :b
30
+ arg :c, type: :array, splat: true
31
+
32
+ def run
33
+ p [a, b, c]
34
+ end
35
+ end
36
+ rb
37
+ -%>
38
+
39
+ <%= run "Cl.new('splat').run(%w(lft 1 2 3 4 5))" %>
40
+
41
+ <%= out '[["1", "2", "3"], "4", "5"]' %>
42
+
43
+ <%= run "Cl.new('splat').run(%w(mid 1 2 3 4 5))" %>
44
+
45
+ <%= out '["1", ["2", "3", "4"], "5"]' %>
46
+
47
+ <%= run "Cl.new('splat').run(%w(rgt 1 2 3 4 5))" %>
48
+
49
+ <%= out '["1", "2", ["3", "4", "5"]]' %>