commandable 0.2.0.beta01
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.
- data/.gitignore +8 -0
- data/Gemfile +2 -0
- data/LICENCE +19 -0
- data/README.markdown +409 -0
- data/Rakefile +29 -0
- data/_testing/alias_trap.rb +14 -0
- data/autotest/discover.rb +2 -0
- data/bin/commandable +18 -0
- data/commandable.gemspec +24 -0
- data/lib/commandable.rb +4 -0
- data/lib/commandable/app_controller.rb +47 -0
- data/lib/commandable/commandable.rb +394 -0
- data/lib/commandable/exceptions.rb +61 -0
- data/lib/commandable/version.rb +4 -0
- data/lib/monkey_patch/file_utils.rb +11 -0
- data/spec/commandable/command_line_execution_spec.rb +154 -0
- data/spec/commandable/commandable_spec.rb +245 -0
- data/spec/commandable/help_generator_spec.rb +169 -0
- data/spec/commandable/helpers_spec.rb +17 -0
- data/spec/commandable/reset_spec.rb +26 -0
- data/spec/commandable/xor_groups_spec.rb +43 -0
- data/spec/source_code_examples/class_command_no_command.rb +27 -0
- data/spec/source_code_examples/class_methods.rb +20 -0
- data/spec/source_code_examples/class_methods_nested.rb +31 -0
- data/spec/source_code_examples/command_no_command.rb +27 -0
- data/spec/source_code_examples/deep_class.rb +14 -0
- data/spec/source_code_examples/default_method.rb +17 -0
- data/spec/source_code_examples/default_method_no_params.rb +17 -0
- data/spec/source_code_examples/multi_line_description.rb +17 -0
- data/spec/source_code_examples/multi_line_description_no_params.rb +17 -0
- data/spec/source_code_examples/no_description.rb +10 -0
- data/spec/source_code_examples/parameter_class.rb +27 -0
- data/spec/source_code_examples/parameter_free.rb +22 -0
- data/spec/source_code_examples/required_methods.rb +18 -0
- data/spec/source_code_examples/super_deep_class.rb +28 -0
- data/spec/source_code_examples/test_class.rb +13 -0
- data/spec/source_code_examples/xor_class.rb +37 -0
- data/spec/source_code_for_errors/class_bad.rb +7 -0
- data/spec/source_code_for_errors/default_method_bad.rb +17 -0
- data/spec/source_code_for_errors/private_methods_bad.rb +10 -0
- data/spec/spec_helper.rb +55 -0
- metadata +140 -0
@@ -0,0 +1,27 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
class ParameterClass
|
5
|
+
extend Commandable
|
6
|
+
|
7
|
+
command "hello world"
|
8
|
+
def foo(int_arg1, number_arg2)
|
9
|
+
[int_arg1, number_arg2]
|
10
|
+
end
|
11
|
+
|
12
|
+
command "look a function"
|
13
|
+
def bar(int_arg1, string_arg2="Number 42")
|
14
|
+
[int_arg1, string_arg2]
|
15
|
+
end
|
16
|
+
|
17
|
+
command "run me for stuff to happen"
|
18
|
+
def qux string_arg1 ="1492", string_arg2 = "I'm a tricky one"
|
19
|
+
[string_arg1, string_arg2]
|
20
|
+
end
|
21
|
+
|
22
|
+
command "I'm another function!"
|
23
|
+
def baz number_arg1, string_arg2 = "blorp", *array_arg3
|
24
|
+
[number_arg1, string_arg2, array_arg3]
|
25
|
+
end
|
26
|
+
|
27
|
+
end
|
@@ -0,0 +1,22 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
class ParameterFree
|
5
|
+
extend Commandable
|
6
|
+
|
7
|
+
command 'this method has no params'
|
8
|
+
def no_parms1
|
9
|
+
"no_parms1"
|
10
|
+
end
|
11
|
+
|
12
|
+
command 'none here either'
|
13
|
+
def no_parms2
|
14
|
+
"no_parms2"
|
15
|
+
end
|
16
|
+
|
17
|
+
command 'nope, still none'
|
18
|
+
def no_parms3
|
19
|
+
"no_parms3"
|
20
|
+
end
|
21
|
+
|
22
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
class RequiredMethods
|
5
|
+
|
6
|
+
extend Commandable
|
7
|
+
|
8
|
+
command :required, 'does some stuff'
|
9
|
+
def required_method(gimmie)
|
10
|
+
gimmie
|
11
|
+
end
|
12
|
+
|
13
|
+
command "another one"
|
14
|
+
def non_required_method(meh)
|
15
|
+
meh
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,28 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
module TopModule
|
5
|
+
class ParentClass
|
6
|
+
module WhatWhat
|
7
|
+
class OhNoYouDian
|
8
|
+
module OhYesIDid
|
9
|
+
module TwoSnapsUpIn
|
10
|
+
class ACircle
|
11
|
+
module Exclamation
|
12
|
+
module OKEvenImBoredNow
|
13
|
+
class DeepDeepClass
|
14
|
+
extend Commandable
|
15
|
+
command 'this is a really deep method call'
|
16
|
+
def super_deep_method
|
17
|
+
"you called a deep method"
|
18
|
+
end
|
19
|
+
end
|
20
|
+
end
|
21
|
+
end
|
22
|
+
end
|
23
|
+
end
|
24
|
+
end
|
25
|
+
end
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
@@ -0,0 +1,37 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
class XorClass
|
5
|
+
extend Commandable
|
6
|
+
|
7
|
+
command 'a normal method'
|
8
|
+
def normal_method
|
9
|
+
"normal_method"
|
10
|
+
end
|
11
|
+
|
12
|
+
command 'another normal method'
|
13
|
+
def normal_method2
|
14
|
+
"normal_method2"
|
15
|
+
end
|
16
|
+
|
17
|
+
command 'part of the default :xor group', :xor, :default
|
18
|
+
def xor_method1
|
19
|
+
"xor_method1"
|
20
|
+
end
|
21
|
+
|
22
|
+
command "also in the default :xor group", :xor
|
23
|
+
def xor_method2
|
24
|
+
"xor_method2"
|
25
|
+
end
|
26
|
+
|
27
|
+
command 'you can also make your own groups', :xor => :xor_group
|
28
|
+
def xor_method3
|
29
|
+
"xor_method3"
|
30
|
+
end
|
31
|
+
|
32
|
+
command "use wantever you want as group names", :xor => :xor_group
|
33
|
+
def xor_method4
|
34
|
+
"xor_method4"
|
35
|
+
end
|
36
|
+
|
37
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
class DefaultMethodsBad
|
5
|
+
extend Commandable
|
6
|
+
|
7
|
+
command 'does some stuff', :default
|
8
|
+
def default_method
|
9
|
+
"default_method"
|
10
|
+
end
|
11
|
+
|
12
|
+
command 'does some other stuff', :default
|
13
|
+
def default_method2
|
14
|
+
"default_method2"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,10 @@
|
|
1
|
+
@@command_options
|
2
|
+
require "commandable"
|
3
|
+
|
4
|
+
# This is just a not so clever way of getting at the instance methods of Commandable
|
5
|
+
# Accessing the private methods of a class/module is a bad idea but I really need to
|
6
|
+
# test them. Plus making a helper module just to test them is also against best practices
|
7
|
+
# so...
|
8
|
+
class PrivateMethods
|
9
|
+
extend Commandable
|
10
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,55 @@
|
|
1
|
+
$:.unshift File.expand_path((File.dirname(__FILE__) + '/../lib'))
|
2
|
+
$:.unshift File.expand_path((File.dirname(__FILE__) + '/source_code_examples'))
|
3
|
+
$:.unshift File.expand_path((File.dirname(__FILE__) + '/source_code_for_errors'))
|
4
|
+
$:.unshift File.expand_path(File.dirname(__FILE__))
|
5
|
+
|
6
|
+
require 'term/ansicolor'
|
7
|
+
require 'rspec'
|
8
|
+
require 'commandable'
|
9
|
+
|
10
|
+
# A note on the specs:
|
11
|
+
# Since Commandable uses singletons the tests sometimes get confused about their state.
|
12
|
+
# I'm working on a way to properly clear every thing out of memory before each test but tests
|
13
|
+
# doesn't pass in autotest try running the test again or run rspec yourself and they'll pass.
|
14
|
+
|
15
|
+
# Debug print
|
16
|
+
module Kernel
|
17
|
+
def dp(value)
|
18
|
+
puts ""
|
19
|
+
puts "*" * 40
|
20
|
+
puts "value: #{value}"
|
21
|
+
puts "&" * 40
|
22
|
+
puts ""
|
23
|
+
end
|
24
|
+
def dpi(value)
|
25
|
+
puts ""
|
26
|
+
puts "*" * 40
|
27
|
+
pp value
|
28
|
+
puts "&" * 40
|
29
|
+
puts ""
|
30
|
+
end
|
31
|
+
end
|
32
|
+
|
33
|
+
# Trap STDOUT and STDERR for testing what a method prints to the terminal
|
34
|
+
def capture_output
|
35
|
+
begin
|
36
|
+
require 'stringio'
|
37
|
+
$o_stdout, $o_stderr = $stdout, $stderr
|
38
|
+
$stdout, $stderr = StringIO.new, StringIO.new
|
39
|
+
yield
|
40
|
+
{:stdout => $stdout.string, :stderr => $stderr.string}
|
41
|
+
ensure
|
42
|
+
$stdout, $stderr = $o_stdout, $o_stderr
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
46
|
+
# Executes a command capturing STDOUT and STDERR as an array representing each line
|
47
|
+
def execute_output_ary(argv)
|
48
|
+
execute_output_s(argv).split(%r{\n})
|
49
|
+
end
|
50
|
+
|
51
|
+
# Executes a command capturing STDOUT and STDERR as one string
|
52
|
+
def execute_output_s(argv)
|
53
|
+
output = capture_output{Commandable.execute(argv)}
|
54
|
+
output[:stdout] + output[:stderr]
|
55
|
+
end
|
metadata
ADDED
@@ -0,0 +1,140 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: commandable
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 0.2.0.beta01
|
5
|
+
prerelease: 6
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Mike Bethany
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
date: 2011-03-17 00:00:00.000000000 -04:00
|
13
|
+
default_executable:
|
14
|
+
dependencies:
|
15
|
+
- !ruby/object:Gem::Dependency
|
16
|
+
name: term-ansicolor-hi
|
17
|
+
requirement: &2154595880 !ruby/object:Gem::Requirement
|
18
|
+
none: false
|
19
|
+
requirements:
|
20
|
+
- - ~>
|
21
|
+
- !ruby/object:Gem::Version
|
22
|
+
version: 1.0.6
|
23
|
+
type: :runtime
|
24
|
+
prerelease: false
|
25
|
+
version_requirements: *2154595880
|
26
|
+
- !ruby/object:Gem::Dependency
|
27
|
+
name: rspec
|
28
|
+
requirement: &2154595380 !ruby/object:Gem::Requirement
|
29
|
+
none: false
|
30
|
+
requirements:
|
31
|
+
- - ~>
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '2.5'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: *2154595380
|
37
|
+
description: Adding command line control to your app is as easy as putting 'command
|
38
|
+
"this command does xyz"' above a method. Parameter lists and a help command are
|
39
|
+
automatically built for you.
|
40
|
+
email:
|
41
|
+
- mikbe.tk@gmail.com
|
42
|
+
executables:
|
43
|
+
- commandable
|
44
|
+
extensions: []
|
45
|
+
extra_rdoc_files: []
|
46
|
+
files:
|
47
|
+
- .gitignore
|
48
|
+
- Gemfile
|
49
|
+
- LICENCE
|
50
|
+
- README.markdown
|
51
|
+
- Rakefile
|
52
|
+
- _testing/alias_trap.rb
|
53
|
+
- autotest/discover.rb
|
54
|
+
- bin/commandable
|
55
|
+
- commandable.gemspec
|
56
|
+
- lib/commandable.rb
|
57
|
+
- lib/commandable/app_controller.rb
|
58
|
+
- lib/commandable/commandable.rb
|
59
|
+
- lib/commandable/exceptions.rb
|
60
|
+
- lib/commandable/version.rb
|
61
|
+
- lib/monkey_patch/file_utils.rb
|
62
|
+
- spec/commandable/command_line_execution_spec.rb
|
63
|
+
- spec/commandable/commandable_spec.rb
|
64
|
+
- spec/commandable/help_generator_spec.rb
|
65
|
+
- spec/commandable/helpers_spec.rb
|
66
|
+
- spec/commandable/reset_spec.rb
|
67
|
+
- spec/commandable/xor_groups_spec.rb
|
68
|
+
- spec/source_code_examples/class_command_no_command.rb
|
69
|
+
- spec/source_code_examples/class_methods.rb
|
70
|
+
- spec/source_code_examples/class_methods_nested.rb
|
71
|
+
- spec/source_code_examples/command_no_command.rb
|
72
|
+
- spec/source_code_examples/deep_class.rb
|
73
|
+
- spec/source_code_examples/default_method.rb
|
74
|
+
- spec/source_code_examples/default_method_no_params.rb
|
75
|
+
- spec/source_code_examples/multi_line_description.rb
|
76
|
+
- spec/source_code_examples/multi_line_description_no_params.rb
|
77
|
+
- spec/source_code_examples/no_description.rb
|
78
|
+
- spec/source_code_examples/parameter_class.rb
|
79
|
+
- spec/source_code_examples/parameter_free.rb
|
80
|
+
- spec/source_code_examples/required_methods.rb
|
81
|
+
- spec/source_code_examples/super_deep_class.rb
|
82
|
+
- spec/source_code_examples/test_class.rb
|
83
|
+
- spec/source_code_examples/xor_class.rb
|
84
|
+
- spec/source_code_for_errors/class_bad.rb
|
85
|
+
- spec/source_code_for_errors/default_method_bad.rb
|
86
|
+
- spec/source_code_for_errors/private_methods_bad.rb
|
87
|
+
- spec/spec_helper.rb
|
88
|
+
has_rdoc: true
|
89
|
+
homepage: http://mikbe.tk
|
90
|
+
licenses: []
|
91
|
+
post_install_message:
|
92
|
+
rdoc_options: []
|
93
|
+
require_paths:
|
94
|
+
- lib
|
95
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
96
|
+
none: false
|
97
|
+
requirements:
|
98
|
+
- - ~>
|
99
|
+
- !ruby/object:Gem::Version
|
100
|
+
version: 1.9.2
|
101
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
102
|
+
none: false
|
103
|
+
requirements:
|
104
|
+
- - ! '>'
|
105
|
+
- !ruby/object:Gem::Version
|
106
|
+
version: 1.3.1
|
107
|
+
requirements: []
|
108
|
+
rubyforge_project:
|
109
|
+
rubygems_version: 1.6.2
|
110
|
+
signing_key:
|
111
|
+
specification_version: 3
|
112
|
+
summary: The easiest way to add command line control to your app.
|
113
|
+
test_files:
|
114
|
+
- autotest/discover.rb
|
115
|
+
- spec/commandable/command_line_execution_spec.rb
|
116
|
+
- spec/commandable/commandable_spec.rb
|
117
|
+
- spec/commandable/help_generator_spec.rb
|
118
|
+
- spec/commandable/helpers_spec.rb
|
119
|
+
- spec/commandable/reset_spec.rb
|
120
|
+
- spec/commandable/xor_groups_spec.rb
|
121
|
+
- spec/source_code_examples/class_command_no_command.rb
|
122
|
+
- spec/source_code_examples/class_methods.rb
|
123
|
+
- spec/source_code_examples/class_methods_nested.rb
|
124
|
+
- spec/source_code_examples/command_no_command.rb
|
125
|
+
- spec/source_code_examples/deep_class.rb
|
126
|
+
- spec/source_code_examples/default_method.rb
|
127
|
+
- spec/source_code_examples/default_method_no_params.rb
|
128
|
+
- spec/source_code_examples/multi_line_description.rb
|
129
|
+
- spec/source_code_examples/multi_line_description_no_params.rb
|
130
|
+
- spec/source_code_examples/no_description.rb
|
131
|
+
- spec/source_code_examples/parameter_class.rb
|
132
|
+
- spec/source_code_examples/parameter_free.rb
|
133
|
+
- spec/source_code_examples/required_methods.rb
|
134
|
+
- spec/source_code_examples/super_deep_class.rb
|
135
|
+
- spec/source_code_examples/test_class.rb
|
136
|
+
- spec/source_code_examples/xor_class.rb
|
137
|
+
- spec/source_code_for_errors/class_bad.rb
|
138
|
+
- spec/source_code_for_errors/default_method_bad.rb
|
139
|
+
- spec/source_code_for_errors/private_methods_bad.rb
|
140
|
+
- spec/spec_helper.rb
|