clone 1.0.0.alpha → 1.0.0.beta

Sign up to get free protection for your applications and to get access to all the features.
Files changed (189) hide show
  1. checksums.yaml +4 -4
  2. data/.gitignore +2 -1
  3. data/Gemfile +1 -0
  4. data/LICENSE.txt +22 -0
  5. data/README.md +22 -1
  6. data/VERSION +1 -1
  7. data/bin/clone +7 -0
  8. data/clone.gemspec +4 -0
  9. data/docs/readme +16 -0
  10. data/docs/readme.txt +5 -0
  11. data/lib/clone.rb +13 -2
  12. data/lib/clone/config/config.rb +19 -0
  13. data/lib/clone/config/config.yml +22 -0
  14. data/lib/clone/config/default_config.yml +20 -0
  15. data/lib/clone/config/require.rb +3 -0
  16. data/lib/clone/config/version.rb +10 -0
  17. data/lib/clone/config/yml.rb +22 -0
  18. data/lib/clone/config/z_defaults.rb +28 -0
  19. data/lib/clone/generator/engine.rb +581 -0
  20. data/lib/clone/generator/terminal.rb +104 -0
  21. data/lib/clone/helpers/helper_methods.rb +251 -0
  22. data/lib/clone/helpers/local_methods.rb +150 -0
  23. data/lib/clone/helpers/require.rb +37 -0
  24. data/module/Marshal.4.8 +0 -0
  25. data/module/Marshal.4.8.Z +0 -0
  26. data/module/gems/commander-4.1.3/.gitignore +6 -0
  27. data/module/gems/commander-4.1.3/.travis.yml +11 -0
  28. data/module/gems/commander-4.1.3/DEVELOPMENT +15 -0
  29. data/module/gems/commander-4.1.3/Gemfile +3 -0
  30. data/module/gems/commander-4.1.3/History.rdoc +345 -0
  31. data/module/gems/commander-4.1.3/Manifest +38 -0
  32. data/module/gems/commander-4.1.3/README.rdoc +375 -0
  33. data/module/gems/commander-4.1.3/Rakefile +10 -0
  34. data/module/gems/commander-4.1.3/bin/commander +55 -0
  35. data/module/gems/commander-4.1.3/commander.gemspec +26 -0
  36. data/module/gems/commander-4.1.3/lib/commander.rb +32 -0
  37. data/module/gems/commander-4.1.3/lib/commander/blank.rb +8 -0
  38. data/module/gems/commander-4.1.3/lib/commander/command.rb +213 -0
  39. data/module/gems/commander-4.1.3/lib/commander/core_ext.rb +3 -0
  40. data/module/gems/commander-4.1.3/lib/commander/core_ext/array.rb +26 -0
  41. data/module/gems/commander-4.1.3/lib/commander/core_ext/object.rb +11 -0
  42. data/module/gems/commander-4.1.3/lib/commander/delegates.rb +13 -0
  43. data/module/gems/commander-4.1.3/lib/commander/help_formatters.rb +8 -0
  44. data/module/gems/commander-4.1.3/lib/commander/help_formatters/base.rb +18 -0
  45. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal.rb +20 -0
  46. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/command_help.erb +35 -0
  47. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal/help.erb +36 -0
  48. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact.rb +12 -0
  49. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/command_help.erb +27 -0
  50. data/module/gems/commander-4.1.3/lib/commander/help_formatters/terminal_compact/help.erb +29 -0
  51. data/module/gems/commander-4.1.3/lib/commander/import.rb +10 -0
  52. data/module/gems/commander-4.1.3/lib/commander/platform.rb +8 -0
  53. data/module/gems/commander-4.1.3/lib/commander/runner.rb +411 -0
  54. data/module/gems/commander-4.1.3/lib/commander/user_interaction.rb +521 -0
  55. data/module/gems/commander-4.1.3/lib/commander/version.rb +3 -0
  56. data/module/gems/commander-4.1.3/spec/command_spec.rb +157 -0
  57. data/module/gems/commander-4.1.3/spec/core_ext/array_spec.rb +20 -0
  58. data/module/gems/commander-4.1.3/spec/core_ext/object_spec.rb +21 -0
  59. data/module/gems/commander-4.1.3/spec/help_formatters/terminal_spec.rb +67 -0
  60. data/module/gems/commander-4.1.3/spec/runner_spec.rb +526 -0
  61. data/module/gems/commander-4.1.3/spec/spec_helper.rb +59 -0
  62. data/module/gems/commander-4.1.3/spec/ui_spec.rb +30 -0
  63. data/module/gems/hello.rb +1 -0
  64. data/module/gems/highline-1.6.19/.gitignore +2 -0
  65. data/module/gems/highline-1.6.19/AUTHORS +3 -0
  66. data/module/gems/highline-1.6.19/CHANGELOG +346 -0
  67. data/module/gems/highline-1.6.19/COPYING +340 -0
  68. data/module/gems/highline-1.6.19/INSTALL +55 -0
  69. data/module/gems/highline-1.6.19/LICENSE +7 -0
  70. data/module/gems/highline-1.6.19/README.rdoc +63 -0
  71. data/module/gems/highline-1.6.19/Rakefile +50 -0
  72. data/module/gems/highline-1.6.19/TODO +6 -0
  73. data/module/gems/highline-1.6.19/examples/ansi_colors.rb +38 -0
  74. data/module/gems/highline-1.6.19/examples/asking_for_arrays.rb +18 -0
  75. data/module/gems/highline-1.6.19/examples/basic_usage.rb +75 -0
  76. data/module/gems/highline-1.6.19/examples/color_scheme.rb +32 -0
  77. data/module/gems/highline-1.6.19/examples/get_character.rb +12 -0
  78. data/module/gems/highline-1.6.19/examples/limit.rb +12 -0
  79. data/module/gems/highline-1.6.19/examples/menus.rb +65 -0
  80. data/module/gems/highline-1.6.19/examples/overwrite.rb +19 -0
  81. data/module/gems/highline-1.6.19/examples/page_and_wrap.rb +322 -0
  82. data/module/gems/highline-1.6.19/examples/password.rb +7 -0
  83. data/module/gems/highline-1.6.19/examples/repeat_entry.rb +21 -0
  84. data/module/gems/highline-1.6.19/examples/trapping_eof.rb +22 -0
  85. data/module/gems/highline-1.6.19/examples/using_readline.rb +17 -0
  86. data/module/gems/highline-1.6.19/highline.gemspec +37 -0
  87. data/module/gems/highline-1.6.19/lib/highline.rb +1012 -0
  88. data/module/gems/highline-1.6.19/lib/highline/color_scheme.rb +134 -0
  89. data/module/gems/highline-1.6.19/lib/highline/compatibility.rb +16 -0
  90. data/module/gems/highline-1.6.19/lib/highline/import.rb +41 -0
  91. data/module/gems/highline-1.6.19/lib/highline/menu.rb +398 -0
  92. data/module/gems/highline-1.6.19/lib/highline/question.rb +475 -0
  93. data/module/gems/highline-1.6.19/lib/highline/simulate.rb +48 -0
  94. data/module/gems/highline-1.6.19/lib/highline/string_extensions.rb +131 -0
  95. data/module/gems/highline-1.6.19/lib/highline/style.rb +181 -0
  96. data/module/gems/highline-1.6.19/lib/highline/system_extensions.rb +222 -0
  97. data/module/gems/highline-1.6.19/setup.rb +1360 -0
  98. data/module/gems/highline-1.6.19/site/.cvsignore +1 -0
  99. data/module/gems/highline-1.6.19/site/highline.css +65 -0
  100. data/module/gems/highline-1.6.19/site/images/logo.png +0 -0
  101. data/module/gems/highline-1.6.19/site/index.html +58 -0
  102. data/module/gems/highline-1.6.19/test/string_methods.rb +32 -0
  103. data/module/gems/highline-1.6.19/test/tc_color_scheme.rb +96 -0
  104. data/module/gems/highline-1.6.19/test/tc_highline.rb +1128 -0
  105. data/module/gems/highline-1.6.19/test/tc_import.rb +52 -0
  106. data/module/gems/highline-1.6.19/test/tc_menu.rb +439 -0
  107. data/module/gems/highline-1.6.19/test/tc_string_extension.rb +20 -0
  108. data/module/gems/highline-1.6.19/test/tc_string_highline.rb +38 -0
  109. data/module/gems/highline-1.6.19/test/tc_style.rb +567 -0
  110. data/module/gems/highline-1.6.19/test/ts_all.rb +16 -0
  111. data/module/latest_specs.4.8 +0 -0
  112. data/module/latest_specs.4.8.gz +0 -0
  113. data/module/prerelease_specs.4.8 +0 -0
  114. data/module/prerelease_specs.4.8.gz +0 -0
  115. data/module/specs.4.8 +0 -0
  116. data/module/specs.4.8.gz +0 -0
  117. data/samples/blather/restlike/Gemfile +4 -0
  118. data/samples/blather/restlike/cmd.yml +1 -0
  119. data/samples/blather/restlike/lib/blather.rb +9 -0
  120. data/samples/blather/restlike/lib/blather/dsl/api.rb +78 -0
  121. data/samples/blather/restlike/lib/blather/dsl/call.rb +13 -0
  122. data/samples/blather/restlike/lib/blather/dsl/client.rb +58 -0
  123. data/samples/blather/restlike/lib/blather/dsl/config.rb +11 -0
  124. data/samples/blather/restlike/lib/blather/dsl/extraDSL.rb +163 -0
  125. data/samples/blather/restlike/lib/blather/meta/require.rb +8 -0
  126. data/samples/blather/restlike/lib/blather/meta/xmpp.yml +5 -0
  127. data/samples/blather/restlike/lib/blather/vendors/xmpp_default.rb +27 -0
  128. data/samples/blather/restlike/readme +2 -0
  129. data/samples/grape/init/Gemfile +2 -0
  130. data/samples/grape/init/cmd.yml +3 -0
  131. data/samples/grape/init/config.ru +2 -0
  132. data/samples/grape/init/docs/grape/documentation.txt +939 -0
  133. data/samples/grape/init/docs/grape/generate_rest_routes.rb +37 -0
  134. data/samples/grape/init/docs/grape/ls_routes.rb +31 -0
  135. data/samples/grape/init/lib/grape.rb +4 -0
  136. data/samples/grape/init/lib/grape/meta/subclasses.rb +20 -0
  137. data/samples/grape/init/lib/grape/xpath/app.rb +30 -0
  138. data/samples/grape/init/lib/grape/xpath/ruotes.rb +6 -0
  139. data/samples/grape/init/readme +1 -0
  140. data/samples/grape/readme +29 -0
  141. data/samples/grape/vendor/lib/grape/vendors/v1/rest.rb +57 -0
  142. data/samples/mongoid/cmd.yml +1 -0
  143. data/samples/mongoid/init/Gemfile +3 -0
  144. data/samples/mongoid/init/cmd.yml +2 -0
  145. data/samples/mongoid/init/docs/mongoid/ModelsRelations.rb +11 -0
  146. data/samples/mongoid/init/docs/mongoid/documents.xls +0 -0
  147. data/samples/mongoid/init/docs/mongoid/generate_modelsToDocs.rb +25 -0
  148. data/samples/mongoid/init/docs/mongoid/modelsToDocs.rb +25 -0
  149. data/samples/mongoid/init/docs/mongoid/relations.txt +1354 -0
  150. data/samples/mongoid/init/lib/mongoid.rb +44 -0
  151. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_CRUD.rb +446 -0
  152. data/samples/mongoid/init/lib/mongoid/dsl/extraDSL_MP.rb +517 -0
  153. data/samples/mongoid/init/lib/mongoid/dsl/init.rb +37 -0
  154. data/samples/mongoid/init/lib/mongoid/dsl/params.rb +67 -0
  155. data/samples/mongoid/init/lib/mongoid/meta/banned.rb +147 -0
  156. data/samples/mongoid/init/lib/mongoid/meta/control.yml +13 -0
  157. data/samples/mongoid/init/lib/mongoid/meta/mongoid.yml +6 -0
  158. data/samples/mongoid/init/lib/mongoid/meta/mpatch.rb +14 -0
  159. data/samples/mongoid/model/lib/mongoid/models/model.rb +28 -0
  160. data/samples/mongoid/readme +33 -0
  161. data/samples/rack/init/Gemfile +10 -0
  162. data/samples/rack/init/cmd.yml +2 -0
  163. data/samples/rack/init/config.ru +1 -0
  164. data/samples/rack/init/docs/rack/rake introducing.txt +60 -0
  165. data/samples/rack/init/docs/rack/webservers/Thin +43 -0
  166. data/samples/rack/init/docs/rack/webservers/ebb +72 -0
  167. data/samples/rack/init/docs/rack/webservers/fcgi +103 -0
  168. data/samples/rack/init/docs/rack/webservers/mongrel +74 -0
  169. data/samples/rack/init/docs/rack/webservers/passenger +37 -0
  170. data/samples/rack/init/docs/rack/webservers/scgi +188 -0
  171. data/samples/rack/init/lib/rack.rb +1 -0
  172. data/samples/rack/init/lib/rack/meta/webserver/thin.rb +45 -0
  173. data/samples/rack/init/lib/rack/meta/webserver/thin.yml +6 -0
  174. data/samples/rack/init/server.rb +0 -0
  175. data/samples/rack/readme +13 -0
  176. data/samples/rest_client/init/Gemfile +5 -0
  177. data/samples/rest_client/init/boot.rb +2 -0
  178. data/samples/rest_client/init/cmd.yml +1 -0
  179. data/samples/rest_client/init/config/rest_client/defaults.rb +16 -0
  180. data/samples/rest_client/init/docs/rest_client/simple overlook +251 -0
  181. data/samples/rest_client/init/test/rest_client/rest_dsl.rb +5 -0
  182. data/samples/rest_client/readme +7 -0
  183. data/samples/scripts/lines_counter/lines_number.rb +32 -0
  184. data/samples/scripts/lines_counter/readme +5 -0
  185. data/samples/scripts/readme +1 -0
  186. metadata +197 -7
  187. data/lib/clone/cms.rb +0 -56
  188. data/lib/clone/ext.rb +0 -77
  189. data/sample/test.rb +0 -30
@@ -0,0 +1,3 @@
1
+ module Commander
2
+ VERSION ||= '4.1.3'
3
+ end
@@ -0,0 +1,157 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commander::Command do
4
+
5
+ before :each do
6
+ mock_terminal
7
+ create_test_command
8
+ end
9
+
10
+ describe 'Options' do
11
+ before :each do
12
+ @options = Commander::Command::Options.new
13
+ end
14
+
15
+ it "should act like an open struct" do
16
+ @options.send = 'mail'
17
+ @options.call = true
18
+ @options.send.should eq('mail')
19
+ @options.call.should eq(true)
20
+ end
21
+
22
+ it "should allow __send__ to function as always" do
23
+ @options.send = 'foo'
24
+ @options.__send__(:send).should eq('foo')
25
+ end
26
+ end
27
+
28
+ describe "#option" do
29
+ it "should add options" do
30
+ lambda { @command.option '--recursive' }.should change(@command.options, :length).from(1).to(2)
31
+ end
32
+
33
+ it "should allow procs as option handlers" do
34
+ @command.option('--recursive') { |recursive| recursive.should be_true }
35
+ @command.run '--recursive'
36
+ end
37
+
38
+ it "should allow usage of common method names" do
39
+ @command.option '--open file'
40
+ @command.when_called { |_, options| options.open.should eq('foo') }
41
+ @command.run '--open', 'foo'
42
+ end
43
+ end
44
+
45
+ describe "#run" do
46
+ describe "should invoke #when_called" do
47
+ it "with arguments seperated from options" do
48
+ @command.when_called { |args, options| args.join(' ').should eq('just some args') }
49
+ @command.run '--verbose', 'just', 'some', 'args'
50
+ end
51
+
52
+ it "calling the #call method by default when an object is called" do
53
+ object = mock 'Object'
54
+ object.should_receive(:call).once
55
+ @command.when_called object
56
+ @command.run 'foo'
57
+ end
58
+
59
+ it "should allow #action as an alias to #when_called" do
60
+ object = mock 'Object'
61
+ object.should_receive(:call).once
62
+ @command.action object
63
+ @command.run 'foo'
64
+ end
65
+
66
+ it "calling an arbitrary method when an object is called" do
67
+ object = mock 'Object'
68
+ object.should_receive(:foo).once
69
+ @command.when_called object, :foo
70
+ @command.run 'foo'
71
+ end
72
+
73
+ it "should raise an error when no handler is present" do
74
+ lambda { @command.when_called }.should raise_error(ArgumentError)
75
+ end
76
+ end
77
+
78
+ describe "should populate options with" do
79
+ it "boolean values" do
80
+ @command.option '--[no-]toggle'
81
+ @command.when_called { |_, options| options.toggle.should be_true }
82
+ @command.run '--toggle'
83
+ @command.when_called { |_, options| options.toggle.should be_false }
84
+ @command.run '--no-toggle'
85
+ end
86
+
87
+ it "mandatory arguments" do
88
+ @command.option '--file FILE'
89
+ @command.when_called { |_, options| options.file.should eq('foo') }
90
+ @command.run '--file', 'foo'
91
+ lambda { @command.run '--file' }.should raise_error(OptionParser::MissingArgument)
92
+ end
93
+
94
+ describe "optional arguments" do
95
+ before do
96
+ @command.option '--use-config [file] '
97
+ end
98
+
99
+ it "should return the argument when provided" do
100
+ @command.when_called { |_, options| options.use_config.should eq('foo') }
101
+ @command.run '--use-config', 'foo'
102
+ end
103
+
104
+ it "should return true when present without an argument" do
105
+ @command.when_called { |_, options| options.use_config.should be_true }
106
+ @command.run '--use-config'
107
+ end
108
+
109
+ it "should return nil when not present" do
110
+ @command.when_called { |_, options| options.use_config.should be_nil }
111
+ @command.run
112
+ end
113
+ end
114
+
115
+ describe "typed arguments" do
116
+ before do
117
+ @command.option '--interval N', Integer
118
+ end
119
+
120
+ it "should parse valid values" do
121
+ @command.when_called { |_, options| options.interval.should eq(5) }
122
+ @command.run '--interval', '5'
123
+ end
124
+
125
+ it "should reject invalid values" do
126
+ lambda { @command.run '--interval', 'invalid' }.should raise_error(OptionParser::InvalidArgument)
127
+ end
128
+ end
129
+
130
+ it "lists" do
131
+ @command.option '--fav COLORS', Array
132
+ @command.when_called { |_, options| options.fav.should eq(['red', 'green', 'blue']) }
133
+ @command.run '--fav', 'red,green,blue'
134
+ end
135
+
136
+ it "lists with multi-word items" do
137
+ @command.option '--fav MOVIES', Array
138
+ @command.when_called { |_, options| options.fav.should eq(['super\ bad', 'nightmare']) }
139
+ @command.run '--fav', 'super\ bad,nightmare'
140
+ end
141
+
142
+ it "defaults" do
143
+ @command.option '--files LIST', Array
144
+ @command.option '--interval N', Integer
145
+ @command.when_called do |_, options|
146
+ options.default \
147
+ :files => ['foo', 'bar'],
148
+ :interval => 5
149
+ options.files.should eq(['foo', 'bar'])
150
+ options.interval.should eq(15)
151
+ end
152
+ @command.run '--interval', '15'
153
+ end
154
+ end
155
+ end
156
+
157
+ end
@@ -0,0 +1,20 @@
1
+ require 'spec_helper'
2
+
3
+ describe Array do
4
+
5
+ describe "#parse" do
6
+ it "should seperate a list of words into an array" do
7
+ Array.parse('just a test').should eq(['just', 'a', 'test'])
8
+ end
9
+
10
+ it "should preserve escaped whitespace" do
11
+ Array.parse('just a\ test').should eq(['just', 'a test'])
12
+ end
13
+
14
+ it "should match %w behavior with multiple backslashes" do
15
+ str = 'just a\\ test'
16
+ Array.parse(str).should eq(eval("%w(#{str})"))
17
+ end
18
+ end
19
+
20
+ end
@@ -0,0 +1,21 @@
1
+ require 'spec_helper'
2
+
3
+ describe Object do
4
+
5
+ describe "#get_binding" do
6
+ it "should return the objects binding" do
7
+ lambda {}.get_binding.should be_instance_of(Binding)
8
+ end
9
+ end
10
+
11
+ describe "#method_missing" do
12
+ it "should preserve its original behavior for missing methods" do
13
+ lambda { i_am_a_missing_method() }.should raise_error(NoMethodError)
14
+ end
15
+
16
+ it "should preserve its original behavior for missing variables" do
17
+ lambda { i_am_a_missing_variable }.should raise_error(NameError)
18
+ end
19
+ end
20
+
21
+ end
@@ -0,0 +1,67 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commander::HelpFormatter::Terminal do
4
+
5
+ before :each do
6
+ mock_terminal
7
+ end
8
+
9
+ describe "global help" do
10
+ before :each do
11
+ new_command_runner 'help' do
12
+ command :'install gem' do |c|
13
+ c.syntax = 'foo install gem [options]'
14
+ c.summary = 'Install some gem'
15
+ end
16
+ end.run!
17
+ @global_help = @output.string
18
+ end
19
+
20
+ describe "should display" do
21
+ it "the command name" do
22
+ @global_help.should include('install gem')
23
+ end
24
+
25
+ it "the summary" do
26
+ @global_help.should include('Install some gem')
27
+ end
28
+ end
29
+ end
30
+
31
+ describe "command help" do
32
+ before :each do
33
+ new_command_runner 'help', 'install', 'gem' do
34
+ command :'install gem' do |c|
35
+ c.syntax = 'foo install gem [options]'
36
+ c.summary = 'Install some gem'
37
+ c.description = 'Install some gem, blah blah blah'
38
+ c.example 'one', 'two'
39
+ c.example 'three', 'four'
40
+ end
41
+ end.run!
42
+ @command_help = @output.string
43
+ end
44
+
45
+ describe "should display" do
46
+ it "the command name" do
47
+ @command_help.should include('install gem')
48
+ end
49
+
50
+ it "the description" do
51
+ @command_help.should include('Install some gem, blah blah blah')
52
+ end
53
+
54
+ it "all examples" do
55
+ @command_help.should include('# one')
56
+ @command_help.should include('two')
57
+ @command_help.should include('# three')
58
+ @command_help.should include('four')
59
+ end
60
+
61
+ it "the syntax" do
62
+ @command_help.should include('foo install gem [options]')
63
+ end
64
+ end
65
+ end
66
+
67
+ end
@@ -0,0 +1,526 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commander do
4
+ before :each do
5
+ $stderr = StringIO.new
6
+ mock_terminal
7
+ create_test_command
8
+ end
9
+
10
+ describe "#program" do
11
+ it "should set / get program information" do
12
+ program :name, 'test'
13
+ program(:name).should eq('test')
14
+ end
15
+
16
+ it "should allow arbitrary blocks of global help documentation" do
17
+ program :help, 'Copyright', 'TJ Holowaychuk'
18
+ program(:help)['Copyright'].should eq('TJ Holowaychuk')
19
+ end
20
+
21
+ it "should raise an error when required info has not been set" do
22
+ new_command_runner '--help'
23
+ program :version, ''
24
+ lambda { run! }.should raise_error(Commander::Runner::CommandError)
25
+ end
26
+
27
+ it "should allow aliases of help formatters" do
28
+ program :help_formatter, :compact
29
+ program(:help_formatter).should eq(Commander::HelpFormatter::TerminalCompact)
30
+ end
31
+ end
32
+
33
+ describe "#command" do
34
+ it "should return a command instance when only the name is passed" do
35
+ command(:meta).should be_instance_of(Commander::Command)
36
+ end
37
+
38
+ it "should return nil when the command does not exist" do
39
+ command(:im_not_real).should be_nil
40
+ end
41
+ end
42
+
43
+ describe "#separate_switches_from_description" do
44
+ it "should seperate switches and description returning both" do
45
+ switches, description = *Commander::Runner.separate_switches_from_description('-h', '--help', 'display help')
46
+ switches.should eq(['-h', '--help'])
47
+ description.should eq('display help')
48
+ end
49
+ end
50
+
51
+ describe "#switch_to_sym" do
52
+ it "should return a symbol based on the switch name" do
53
+ Commander::Runner.switch_to_sym('--trace').should eq(:trace)
54
+ Commander::Runner.switch_to_sym('--foo-bar').should eq(:foo_bar)
55
+ Commander::Runner.switch_to_sym('--[no-]feature"').should eq(:feature)
56
+ Commander::Runner.switch_to_sym('--[no-]feature ARG').should eq(:feature)
57
+ Commander::Runner.switch_to_sym('--file [ARG]').should eq(:file)
58
+ Commander::Runner.switch_to_sym('--colors colors').should eq(:colors)
59
+ end
60
+ end
61
+
62
+ describe "#alias_command" do
63
+ it "should alias a command" do
64
+ alias_command :foo, :meta
65
+ command(:foo).should eq(command(:meta))
66
+ end
67
+
68
+ it "should pass arguments passed to the alias when called" do
69
+ gem_name = ''
70
+ new_command_runner 'install', 'gem', 'commander' do
71
+ command :install do |c|
72
+ c.option '--gem-name NAME', 'Install a gem'
73
+ c.when_called { |_, options| gem_name = options.gem_name }
74
+ end
75
+ alias_command :'install gem', :install, '--gem-name'
76
+ end.run!
77
+ gem_name.should eq('commander')
78
+ end
79
+ end
80
+
81
+ describe "#global_option" do
82
+ it "should be invoked when used in the args list" do
83
+ file = ''
84
+ new_command_runner 'test', '--config', 'foo' do
85
+ global_option('--config FILE') { |f| file = f }
86
+ end.run!
87
+ file.should eq('foo')
88
+ end
89
+
90
+ it "should be inherited by commands" do
91
+ quiet = nil
92
+ new_command_runner 'foo', '--quiet' do
93
+ global_option('--quiet', 'Suppress output')
94
+ command :foo do |c|
95
+ c.when_called { |_, options| quiet = options.quiet }
96
+ end
97
+ end.run!
98
+ quiet.should be_true
99
+ end
100
+
101
+ it "should be inherited by commands even when a block is present" do
102
+ quiet = nil
103
+ new_command_runner 'foo', '--quiet' do
104
+ global_option('--quiet', 'Suppress output') {}
105
+ command :foo do |c|
106
+ c.when_called { |_, options| quiet = options.quiet }
107
+ end
108
+ end.run!
109
+ quiet.should be_true
110
+ end
111
+ end
112
+
113
+ describe "#parse_global_options" do
114
+ it 'should parse global options before command' do
115
+ global_option = nil
116
+ new_command_runner('--testing-global', 'foo') do
117
+ global_option('--testing-global') { global_option = 'MAGIC' }
118
+
119
+ command :foo do |c|
120
+ c.when_called {}
121
+ end
122
+ end.run!
123
+ global_option.should eq('MAGIC')
124
+ end
125
+
126
+ it 'should parse global options after command' do
127
+ global_option = nil
128
+ new_command_runner('foo','--testing-global') do
129
+ global_option('--testing-global') { global_option = 'MAGIC' }
130
+
131
+ command :foo do |c|
132
+ c.when_called {}
133
+ end
134
+ end.run!
135
+ global_option.should eq('MAGIC')
136
+ end
137
+
138
+ it 'should parse global options placed before command options' do
139
+ global_option = nil
140
+ new_command_runner('foo', '--testing-global', '--testing-command') do
141
+ global_option('--testing-global') { global_option = 'MAGIC' }
142
+
143
+ command :foo do |c|
144
+ c.option('--testing-command') {}
145
+ c.when_called {}
146
+ end
147
+ end.run!
148
+
149
+ global_option.should eq('MAGIC')
150
+ end
151
+
152
+ it 'should parse global options placed after command options' do
153
+ global_option = nil
154
+ new_command_runner('foo', '--testing-command', '--testing-global') do
155
+ global_option('--testing-global') { global_option = 'MAGIC' }
156
+
157
+ command :foo do |c|
158
+ c.option('--testing-command') {}
159
+ c.when_called {}
160
+ end
161
+ end.run!
162
+
163
+ global_option.should eq('MAGIC')
164
+ end
165
+
166
+ it 'should parse global options surrounded by command options' do
167
+ global_option = nil
168
+ new_command_runner('foo', '--testing-command', '--testing-global', '--other-command') do
169
+ global_option('--testing-global') { global_option = 'MAGIC' }
170
+
171
+ command :foo do |c|
172
+ c.option('--testing-command') {}
173
+ c.option('--other-command') {}
174
+ c.when_called {}
175
+ end
176
+ end.run!
177
+
178
+ global_option.should eq('MAGIC')
179
+ end
180
+
181
+ it 'should not parse command options' do
182
+ global_option = nil
183
+ command_option = nil
184
+ new_command_runner('foo', '--testing-command', '--testing-global') do
185
+ global_option('--testing-global') { global_option = 'MAGIC' }
186
+
187
+ command :foo do |c|
188
+ c.option('--testing-command') { command_option = 'NO!' }
189
+ c.when_called {}
190
+ end
191
+ end.parse_global_options
192
+
193
+ command_option.should be_nil
194
+ global_option.should eq('MAGIC')
195
+ end
196
+
197
+ it 'should not affect command arguments with values' do
198
+ global_option = nil
199
+ command_option = nil
200
+ new_command_runner('foo', '--testing-command', 'bar', '--testing-global') do
201
+ global_option('--testing-global') { global_option = 'MAGIC' }
202
+
203
+ command :foo do |c|
204
+ c.option('--testing-command VALUE') { |v| command_option = v }
205
+ c.when_called {}
206
+ end
207
+ end.run!
208
+
209
+ command_option.should eq('bar')
210
+ global_option.should eq('MAGIC')
211
+ end
212
+
213
+ it 'should not affect global arguments with values' do
214
+ global_option = nil
215
+ new_command_runner('foo', '--testing-command', '--testing-global', 'bar') do
216
+ global_option('--testing-global VALUE') { |v| global_option = v }
217
+
218
+ command :foo do |c|
219
+ c.option('--testing-command') { }
220
+ c.when_called {}
221
+ end
222
+ end.run!
223
+
224
+ global_option.should eq('bar')
225
+ end
226
+
227
+ it 'should allow global arguments with values before command arguments (github issue #8)' do
228
+ global_option = nil
229
+ command_option = nil
230
+ new_command_runner('foo', '--config', 'path', 'bar') do
231
+ global_option('--config VALUE') { |v| global_option = v }
232
+
233
+ command :foo do |c|
234
+ c.option('bar') { command_option = 'bar' }
235
+ c.when_called {}
236
+ end
237
+ end.run!
238
+
239
+ global_option.should eq('path')
240
+ command_option.should eq('bar')
241
+ end
242
+ end
243
+
244
+
245
+ describe "#remove_global_options" do
246
+ it "should remove only specified switches" do
247
+ options, args = [], []
248
+ options << { :switches => ['-t', '--trace'] }
249
+ options << { :switches => ['--help'] }
250
+ options << { :switches => ['--paths PATHS'] }
251
+ args << '-t'
252
+ args << '--help'
253
+ args << '--command'
254
+ args << '--command-with-arg' << 'rawr'
255
+ args << '--paths' << '"lib/**/*.js","spec/**/*.js"'
256
+ command_runner.remove_global_options options, args
257
+ args.should eq(['--command', '--command-with-arg', 'rawr'])
258
+ end
259
+
260
+ it "should not swallow an argument unless it expects an argument" do
261
+ options, args = [], []
262
+ options << { :switches => ['-n', '--no-arg'] }
263
+ options << { :switches => ['-y', '--yes ARG'] }
264
+ options << { :switches => ['-a', '--alternative=ARG'] }
265
+ args << '-n' << 'alpha'
266
+ args << '--yes' << 'deleted'
267
+ args << '-a' << 'deleted'
268
+ args << 'beta'
269
+ command_runner.remove_global_options options, args
270
+ args.should eq(['alpha', 'beta'])
271
+ end
272
+ end
273
+
274
+ describe "--trace" do
275
+ it "should display pretty errors by default" do
276
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
277
+ lambda {
278
+ new_command_runner 'foo' do
279
+ command(:foo) { |c| c.when_called { raise 'cookies!' } }
280
+ end.run!
281
+ }.should raise_error(SystemExit, /error: cookies!. Use --trace/)
282
+ end
283
+
284
+ it "should display callstack when using this switch" do
285
+ lambda {
286
+ new_command_runner 'foo', '--trace' do
287
+ command(:foo) { |c| c.when_called { raise 'cookies!' } }
288
+ end.run!
289
+ }.should raise_error(RuntimeError)
290
+ end
291
+ end
292
+
293
+ describe "--version" do
294
+ it "should output program version" do
295
+ run('--version').should eq("test 1.2.3\n")
296
+ end
297
+ end
298
+
299
+ describe "--help" do
300
+ it "should not output an invalid command message" do
301
+ run('--help').should_not == "invalid command. Use --help for more information\n"
302
+ end
303
+
304
+ it "can be used before or after the command and options" do
305
+ run('test', '--help').should eq("Implement help for test here\n")
306
+ end
307
+ end
308
+
309
+ describe "with invalid options" do
310
+ it "should output an invalid option message" do
311
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
312
+ lambda {
313
+ run('test', '--invalid-option')
314
+ }.should raise_error(SystemExit, /invalid option: --invalid-option/)
315
+ end
316
+ end
317
+
318
+ describe "with invalid command passed" do
319
+ it "should output an invalid command message" do
320
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
321
+ lambda {
322
+ run('foo')
323
+ }.should raise_error(SystemExit, /invalid command. Use --help for more information/)
324
+ end
325
+ end
326
+
327
+ describe "with invalid command passed to help" do
328
+ it "should output an invalid command message" do
329
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
330
+ lambda {
331
+ run('help', 'does_not_exist')
332
+ }.should raise_error(SystemExit, /invalid command. Use --help for more information/)
333
+ end
334
+ end
335
+
336
+ describe "with invalid command passed to --help" do
337
+ it "should output an invalid command message" do
338
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
339
+ lambda {
340
+ run('--help', 'does_not_exist')
341
+ }.should raise_error(SystemExit, /invalid command. Use --help for more information/)
342
+ end
343
+ end
344
+
345
+ describe "with invalid option passed to --help" do
346
+ it "should output an invalid option message" do
347
+ pending("JRuby's Kernel.abort implementation is not testable") if Commander::Platform::jruby?
348
+ lambda {
349
+ run('--help', 'test', '--invalid-option')
350
+ }.should raise_error(SystemExit, /invalid option: --invalid-option/)
351
+ end
352
+ end
353
+
354
+ describe "#valid_command_names_from" do
355
+ it "should return array of valid command names" do
356
+ command('foo bar') {}
357
+ command('foo bar foo') {}
358
+ command_runner.valid_command_names_from('foo', 'bar', 'foo').sort.should eq(['foo bar', 'foo bar foo'])
359
+ end
360
+
361
+ it "should return empty array when no possible command names exist" do
362
+ command_runner.valid_command_names_from('fake', 'command', 'name').should eq([])
363
+ end
364
+
365
+ it "should match exact commands only" do
366
+ command('foo') {}
367
+ command_runner.valid_command_names_from('foobar').should eq([])
368
+ end
369
+ end
370
+
371
+ describe "#command_name_from_args" do
372
+ it "should locate command within arbitrary arguments passed" do
373
+ new_command_runner '--help', '--arbitrary', 'test'
374
+ command_runner.command_name_from_args.should eq('test')
375
+ end
376
+
377
+ it "should support multi-word commands" do
378
+ new_command_runner '--help', '--arbitrary', 'some', 'long', 'command', 'foo'
379
+ command('some long command') {}
380
+ command_runner.command_name_from_args.should eq('some long command')
381
+ end
382
+
383
+ it "should match the longest possible command" do
384
+ new_command_runner '--help', '--arbitrary', 'foo', 'bar', 'foo'
385
+ command('foo bar') {}
386
+ command('foo bar foo') {}
387
+ command_runner.command_name_from_args.should eq('foo bar foo' )
388
+ end
389
+
390
+ it "should use the left-most command name when multiple are present" do
391
+ new_command_runner 'help', 'test'
392
+ command_runner.command_name_from_args.should eq('help' )
393
+ end
394
+ end
395
+
396
+ describe "#active_command" do
397
+ it "should resolve the active command" do
398
+ new_command_runner '--help', 'test'
399
+ command_runner.active_command.should be_instance_of(Commander::Command)
400
+ end
401
+
402
+ it "should resolve active command when invalid options are passed" do
403
+ new_command_runner '--help', 'test', '--arbitrary'
404
+ command_runner.active_command.should be_instance_of(Commander::Command)
405
+ end
406
+
407
+ it "should return nil when the command is not found" do
408
+ new_command_runner 'foo'
409
+ command_runner.active_command.should be_nil
410
+ end
411
+ end
412
+
413
+ describe "#default_command" do
414
+ it "should allow you to default any command when one is not explicitly passed" do
415
+ new_command_runner '--trace' do
416
+ default_command :meta
417
+ command(:meta).should_receive(:run).once
418
+ command_runner.active_command.should eq(command(:meta))
419
+ end.run!
420
+ end
421
+
422
+ it "should not prevent other commands from being called" do
423
+ new_command_runner 'foo', 'bar', '--trace' do
424
+ default_command :meta
425
+ command(:'foo bar'){}
426
+ command(:'foo bar').should_receive(:run).once
427
+ command_runner.active_command.should eq(command(:'foo bar'))
428
+ end.run!
429
+ end
430
+
431
+ it "should not prevent longer commands to use the same words as the default" do
432
+ new_command_runner 'foo', 'bar', 'something'
433
+ default_command :'foo bar'
434
+ command(:'foo bar'){}
435
+ command(:'foo bar something'){}
436
+ command_runner.active_command.should eq(command(:'foo bar something'))
437
+ end
438
+
439
+ it "should allow defaulting of command aliases" do
440
+ new_command_runner '--trace' do
441
+ default_command :foobar
442
+ alias_command :foobar, :meta
443
+ command(:meta).should_receive(:run).once
444
+ end.run!
445
+ end
446
+ end
447
+
448
+ describe "should function correctly" do
449
+ it "when options are passed before the command name" do
450
+ new_command_runner '--verbose', 'test', 'foo', 'bar' do
451
+ @command.when_called do |args, options|
452
+ args.should eq(['foo', 'bar'])
453
+ options.verbose.should be_true
454
+ end
455
+ end.run!
456
+ end
457
+
458
+ it "when options are passed after the command name" do
459
+ new_command_runner 'test', '--verbose', 'foo', 'bar' do
460
+ @command.when_called do |args, options|
461
+ args.should eq(['foo', 'bar'])
462
+ options.verbose.should be_true
463
+ end
464
+ end.run!
465
+ end
466
+
467
+ it "when an argument passed is the same name as the command" do
468
+ new_command_runner 'test', '--verbose', 'foo', 'test', 'bar' do
469
+ @command.when_called do |args, options|
470
+ args.should eq(['foo', 'test', 'bar'])
471
+ options.verbose.should be_true
472
+ end
473
+ end.run!
474
+ end
475
+
476
+ it "when using multi-word commands" do
477
+ new_command_runner '--verbose', 'my', 'command', 'something', 'foo', 'bar' do
478
+ command('my command') { |c| c.option('--verbose') }
479
+ command_runner.command_name_from_args.should eq('my command')
480
+ command_runner.args_without_command_name.should eq(['--verbose', 'something', 'foo', 'bar'])
481
+ end.run!
482
+ end
483
+
484
+ it "when using multi-word commands with parts of the command name as arguments" do
485
+ new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
486
+ command('my command') { |c| c.option('--verbose') }
487
+ command_runner.command_name_from_args.should eq('my command')
488
+ command_runner.args_without_command_name.should eq(['--verbose', 'something', 'my', 'command'])
489
+ end.run!
490
+ end
491
+
492
+ it "when using multi-word commands with other commands using the same words" do
493
+ new_command_runner '--verbose', 'my', 'command', 'something', 'my', 'command' do
494
+ command('my command') {}
495
+ command('my command something') { |c| c.option('--verbose') }
496
+ command_runner.command_name_from_args.should eq('my command something')
497
+ command_runner.args_without_command_name.should eq(['--verbose', 'my', 'command'])
498
+ end.run!
499
+ end
500
+ end
501
+
502
+ describe "options with optional arguments" do
503
+ it "should return the argument when it is specified" do
504
+ new_command_runner 'foo', '--optional', 'arg1' do
505
+ command('foo') do |c|
506
+ c.option('--optional [argument]')
507
+ c.when_called do |_, options|
508
+ options.optional.should eq('arg1')
509
+ end
510
+ end
511
+ end.run!
512
+ end
513
+
514
+ it "should return true when no argument is specified for the option" do
515
+ new_command_runner 'foo', '--optional' do
516
+ command('foo') do |c|
517
+ c.option('--optional [argument]')
518
+ c.when_called do |_, options|
519
+ options.optional.should be_true
520
+ end
521
+ end
522
+ end.run!
523
+ end
524
+ end
525
+
526
+ end