commandable 0.2.1 → 0.2.2

Sign up to get free protection for your applications and to get access to all the features.
data/README.markdown CHANGED
@@ -36,11 +36,11 @@ And of course upload them when it asks you if it can. You can take a look at the
36
36
  Thanks for your help.
37
37
 
38
38
 
39
- ## Status
39
+ ## Latest version
40
40
 
41
- 2011-04-04 - Version: 0.2.1
41
+ 2011-08-31 - Version: 0.2.2
42
42
 
43
- See change history for additions.
43
+ See change history for specific changes.
44
44
 
45
45
  ## Principle of Least Surprise
46
46
 
@@ -49,7 +49,7 @@ I've tried to follow the principle of least surprise so Commandable should just
49
49
  ## Requirements ##
50
50
 
51
51
  * Ruby 1.9.2
52
- * Any Posix OS (It works, mostly, on Windows but ironically some of the tests won't run because of some unix commands I use in the tests)
52
+ * OS X or any Posix OS (It works, mostly, on Windows but ironically some of the tests won't run because of some Unix commands I use in the tests)
53
53
 
54
54
  ## Installation
55
55
  From the command line:
@@ -198,7 +198,7 @@ Note: Class methods are called directly on the class while instance methods have
198
198
 
199
199
  ### Automatic usage/help generation ###
200
200
 
201
- One of the great features of **Commandable** is that automatically creates usage instructions based on your methods and the descriptions you provide for them and it adds a `help` command for you.
201
+ One of the great features of **Commandable** is that it automatically creates usage instructions based on your methods and the descriptions you provide for them. It then adds a `help` command for you that will print out these usage instructions when called.
202
202
 
203
203
  If your app has no `:default` method or it has a default command that requires parameters the help/usage instructions will be printed if a user just runs your app without any input.
204
204
 
@@ -268,7 +268,7 @@ The help information can be colored using the standard ANSI escape commands foun
268
268
 
269
269
  Then you can do something like this:
270
270
 
271
- require 'term/ansicolor'
271
+ require 'term/ansicolorhi'
272
272
 
273
273
  c = Term::ANSIColorHI
274
274
 
@@ -403,6 +403,11 @@ You just need to configure your bin file with the app settings and then run `Com
403
403
  # See the Widget app for an example of this.
404
404
  require 'yourappname'
405
405
  Commandable.execute(ARGV)
406
+
407
+ # If you don't want the output from your methods to be printed automatically
408
+ # for instance if your method already outputs some text, you can add :silent
409
+ # to the execute command like this:
410
+ # Commandable.execute(ARGV, :silent)
406
411
 
407
412
 
408
413
  I actually prefer to create a separate file for my **Commandable** configuration and load it in my main app file in the `lib` directory. Again, take a look at `Widget` to see what I mean.
@@ -422,6 +427,11 @@ Most of all it should be simple to use so if you have any problems please drop m
422
427
 
423
428
  ## Version History ##
424
429
 
430
+ 2011-08-31 - Version: 0.2.2
431
+
432
+ * Added ability to do use Kernel.exit without Commandable trapping the error.
433
+ * Kernel.exit properly forwards exit status if given one.
434
+
425
435
  2011-04-04 - Version: 0.2.1
426
436
 
427
437
  * Added ability to use attr\_accessor and att\_writer as commands. You can only write to them of course but it's an easy way to set values.
@@ -142,8 +142,11 @@ module Commandable
142
142
  end
143
143
 
144
144
  # A wrapper for the execution_queue that runs the queue and traps errors.
145
- # If an error occurs inside this method it will print out a complete.
146
- # of availavle methods with usage instructios and exit gracefully.
145
+ # If an error occurs inside this method it will print out a complete list
146
+ # of availavle methods with usage instructions and exit gracefully.
147
+ #
148
+ # If you do not want the output from your methods to be printed out automatically
149
+ # run the execute command with silent set to anything other than false or nil.
147
150
  def execute(argv, silent=false)
148
151
  begin
149
152
  command_queue = execution_queue(argv)
@@ -151,6 +154,8 @@ module Commandable
151
154
  return_value = com[:proc].call
152
155
  puts return_value unless silent
153
156
  end
157
+ rescue SystemExit => kernel_exit
158
+ Kernel.exit kernel_exit.status
154
159
  rescue Exception => exception
155
160
  if exception.respond_to?(:friendly_name)
156
161
  set_colors
@@ -2,7 +2,7 @@ module Commandable
2
2
  module VERSION # :nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 2
5
- TINY = 1
5
+ TINY = 2
6
6
  PRE = nil
7
7
 
8
8
  STRING = [MAJOR, MINOR, TINY, PRE].compact.join('.')
@@ -1,11 +1,11 @@
1
- require 'fileutils'
1
+ require 'fileutils'
2
2
 
3
- module FileUtils
4
- # Monkeypatch FileUtils really annoying lack of proper directory copying
5
- def copy_dir(source, dest)
6
- files = Dir.glob("#{source}/**")
7
- mkdir_p dest
8
- cp_r files, dest
9
- end
10
- module_function :copy_dir
11
- end
3
+ module FileUtils
4
+ # Monkeypatch FileUtils really annoying lack of proper directory copying
5
+ def copy_dir(source, dest)
6
+ files = Dir.glob("#{source}/**")
7
+ mkdir_p dest
8
+ cp_r files, dest
9
+ end
10
+ module_function :copy_dir
11
+ end
@@ -19,7 +19,7 @@ describe Commandable do
19
19
 
20
20
  context "when checking syntax" do
21
21
 
22
- it "shouldn't rasie an error if nothing more than 'switch' is used" do
22
+ it "shouldn't raise an error if nothing more than 'switch' is used" do
23
23
  lambda{load 'no_description.rb'}.should_not raise_error(Commandable::SyntaxError)
24
24
  end
25
25
 
@@ -0,0 +1,27 @@
1
+ require 'spec_helper'
2
+
3
+ describe Commandable do
4
+
5
+ before(:each) {
6
+ Commandable.reset_all
7
+ Commandable.app_exe = "mycoolapp"
8
+ Commandable.app_info =
9
+ """
10
+ My Cool App - It does stuff and things!
11
+ Copyright (c) 2011 Acme Inc.
12
+ """
13
+
14
+ load 'kernel_exit_class.rb'
15
+ }
16
+
17
+ it "should not trap kernel exits" do
18
+ lambda{execute_queue(['exit'])}.should raise_error(SystemExit)
19
+ end
20
+
21
+ it "should forward kernel exit status codes" do
22
+ lambda{execute_queue(['exit', '40'])}.should raise_error(SystemExit) { |error|
23
+ error.status.should == 40
24
+ }
25
+ end
26
+
27
+ end
@@ -0,0 +1,10 @@
1
+ require "commandable"
2
+
3
+ class KernelExitClass
4
+
5
+ extend Commandable
6
+ command 'does some stuff'
7
+ def exit(exit_code = 0)
8
+ Kernel.exit exit_code.to_i
9
+ end
10
+ end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: commandable
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,12 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-04-04 00:00:00.000000000 -04:00
13
- default_executable:
12
+ date: 2011-08-31 00:00:00.000000000Z
14
13
  dependencies:
15
14
  - !ruby/object:Gem::Dependency
16
15
  name: term-ansicolor-hi
17
- requirement: &2153496380 !ruby/object:Gem::Requirement
16
+ requirement: &70343654860340 !ruby/object:Gem::Requirement
18
17
  none: false
19
18
  requirements:
20
19
  - - ~>
@@ -22,10 +21,10 @@ dependencies:
22
21
  version: 1.0.7
23
22
  type: :runtime
24
23
  prerelease: false
25
- version_requirements: *2153496380
24
+ version_requirements: *70343654860340
26
25
  - !ruby/object:Gem::Dependency
27
26
  name: rspec
28
- requirement: &2153495800 !ruby/object:Gem::Requirement
27
+ requirement: &70343654859880 !ruby/object:Gem::Requirement
29
28
  none: false
30
29
  requirements:
31
30
  - - ~>
@@ -33,10 +32,10 @@ dependencies:
33
32
  version: '2.5'
34
33
  type: :development
35
34
  prerelease: false
36
- version_requirements: *2153495800
35
+ version_requirements: *70343654859880
37
36
  - !ruby/object:Gem::Dependency
38
37
  name: cucumber
39
- requirement: &2153495200 !ruby/object:Gem::Requirement
38
+ requirement: &70343654859420 !ruby/object:Gem::Requirement
40
39
  none: false
41
40
  requirements:
42
41
  - - ~>
@@ -44,10 +43,10 @@ dependencies:
44
43
  version: '0.10'
45
44
  type: :development
46
45
  prerelease: false
47
- version_requirements: *2153495200
46
+ version_requirements: *70343654859420
48
47
  - !ruby/object:Gem::Dependency
49
48
  name: aruba
50
- requirement: &2153494600 !ruby/object:Gem::Requirement
49
+ requirement: &70343654858960 !ruby/object:Gem::Requirement
51
50
  none: false
52
51
  requirements:
53
52
  - - ~>
@@ -55,7 +54,7 @@ dependencies:
55
54
  version: '0.3'
56
55
  type: :development
57
56
  prerelease: false
58
- version_requirements: *2153494600
57
+ version_requirements: *70343654858960
59
58
  description: ! 'The easiest way to add command line control to your Ruby app. You
60
59
  can add a single line above an existing method and that method will be available
61
60
  from the command line.
@@ -93,7 +92,6 @@ files:
93
92
  - lib/commandable/exceptions.rb
94
93
  - lib/commandable/version.rb
95
94
  - lib/monkey_patch/file_utils.rb
96
- - lib/monkey_patch/os.rb
97
95
  - spec/commandable/app_controller_spec.rb
98
96
  - spec/commandable/attr_accessor_spec.rb
99
97
  - spec/commandable/command_line_execution_spec.rb
@@ -101,6 +99,7 @@ files:
101
99
  - spec/commandable/help_generator_spec.rb
102
100
  - spec/commandable/helpers_spec.rb
103
101
  - spec/commandable/instance_methods_spec.rb
102
+ - spec/commandable/kernel_exit_spec.rb
104
103
  - spec/commandable/required_default_spec.rb
105
104
  - spec/commandable/reset_spec.rb
106
105
  - spec/commandable/xor_groups_spec.rb
@@ -116,6 +115,7 @@ files:
116
115
  - spec/source_code_examples/default_method_no_params.rb
117
116
  - spec/source_code_examples/instance_methods.rb
118
117
  - spec/source_code_examples/instance_methods2.rb
118
+ - spec/source_code_examples/kernel_exit_class.rb
119
119
  - spec/source_code_examples/multi_line_description.rb
120
120
  - spec/source_code_examples/multi_line_description_no_params.rb
121
121
  - spec/source_code_examples/no_description.rb
@@ -130,7 +130,6 @@ files:
130
130
  - spec/source_code_for_errors/default_method_bad.rb
131
131
  - spec/source_code_for_errors/private_methods_bad.rb
132
132
  - spec/spec_helper.rb
133
- has_rdoc: true
134
133
  homepage: http://mikbe.tk
135
134
  licenses:
136
135
  - MIT
@@ -152,7 +151,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
152
151
  version: '0'
153
152
  requirements: []
154
153
  rubyforge_project:
155
- rubygems_version: 1.6.2
154
+ rubygems_version: 1.8.7
156
155
  signing_key:
157
156
  specification_version: 3
158
157
  summary: The easiest way to add command line control to your Ruby apps.
@@ -165,6 +164,7 @@ test_files:
165
164
  - spec/commandable/help_generator_spec.rb
166
165
  - spec/commandable/helpers_spec.rb
167
166
  - spec/commandable/instance_methods_spec.rb
167
+ - spec/commandable/kernel_exit_spec.rb
168
168
  - spec/commandable/required_default_spec.rb
169
169
  - spec/commandable/reset_spec.rb
170
170
  - spec/commandable/xor_groups_spec.rb
@@ -180,6 +180,7 @@ test_files:
180
180
  - spec/source_code_examples/default_method_no_params.rb
181
181
  - spec/source_code_examples/instance_methods.rb
182
182
  - spec/source_code_examples/instance_methods2.rb
183
+ - spec/source_code_examples/kernel_exit_class.rb
183
184
  - spec/source_code_examples/multi_line_description.rb
184
185
  - spec/source_code_examples/multi_line_description_no_params.rb
185
186
  - spec/source_code_examples/no_description.rb
@@ -1,8 +0,0 @@
1
- require 'sys/uname'
2
- include Sys
3
-
4
- module Kernel
5
- def is_windows?
6
- Uname.sysname.downcase.include?('windows')
7
- end
8
- end