subcommander 1.0.4 → 1.1.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.
- data/README.markdown +39 -39
- data/lib/subcommander.rb +3 -2
- metadata +4 -9
data/README.markdown
CHANGED
@@ -6,7 +6,7 @@ More description coming... this is basically a placeholder for now.
|
|
6
6
|
|
7
7
|
### Simple Example:
|
8
8
|
|
9
|
-
|
9
|
+
%w[rubygems subcommander].each { |m| require m }
|
10
10
|
include Subcommander
|
11
11
|
|
12
12
|
subcommander.version = '1.0.0'
|
@@ -15,12 +15,12 @@ More description coming... this is basically a placeholder for now.
|
|
15
15
|
subcommand :run, "Runs the simple tool" do |sc|
|
16
16
|
sc.opt :just_kidding, '-k', '--just-kidding', "Don't really run the simple tool"
|
17
17
|
sc.exec {
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
18
|
+
# This is where the subcommand has its implementation
|
19
|
+
if sc[:just_kidding]
|
20
|
+
puts "Not really running"
|
21
|
+
else
|
22
|
+
puts "Running!"
|
23
|
+
end
|
24
24
|
}
|
25
25
|
end
|
26
26
|
|
@@ -28,38 +28,38 @@ More description coming... this is basically a placeholder for now.
|
|
28
28
|
|
29
29
|
### Nested Subcommands Example:
|
30
30
|
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
46
|
-
|
47
|
-
|
48
|
-
|
49
|
-
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
31
|
+
%w[rubygems subcommander].each { |m| require m }
|
32
|
+
include Subcommander
|
33
|
+
|
34
|
+
subcommander.version = '1.0.0'
|
35
|
+
subcommander.desc = "ComplexTool is ephemeral and only here to demonstrate Subcommander."
|
36
|
+
|
37
|
+
subcommand :run, "Commands for running the complex tool" do |run|
|
38
|
+
run.subcommand 'on-foot', "Run down the street" do |sc|
|
39
|
+
sc.usage = "complextool run on-foot [-f | -s]"
|
40
|
+
sc.opt :fast, '-f', '--fast', "Run fast!"
|
41
|
+
sc.opt :slow, '-s', '--slow', "Run slow."
|
42
|
+
sc.exec {
|
43
|
+
speed = "at a normal pace"
|
44
|
+
if sc[:fast]
|
45
|
+
speed = 'fast'
|
46
|
+
elsif sc[:slow]
|
47
|
+
speed = 'slow'
|
48
|
+
end
|
49
|
+
puts "We're running #{speed}"
|
50
|
+
}
|
51
|
+
end
|
52
|
+
run.subcommand 'an-app', "Run an app" do |sc|
|
53
|
+
sc.arity = 1
|
54
|
+
sc.usage = "complextool run an-app NAME"
|
55
|
+
sc.exec {
|
56
|
+
app = sc[:args][0]
|
57
|
+
puts "Running #{app}"
|
58
|
+
}
|
59
|
+
end
|
60
|
+
end
|
61
|
+
|
62
|
+
subcommander.go!
|
63
63
|
|
64
64
|
---------------------------
|
65
65
|
|
data/lib/subcommander.rb
CHANGED
@@ -130,7 +130,7 @@ module Subcommander
|
|
130
130
|
return
|
131
131
|
end
|
132
132
|
parse_args()
|
133
|
-
num_remaining = @props[:
|
133
|
+
num_remaining = @props[:args].length
|
134
134
|
if @arity > -1 && num_remaining != @arity
|
135
135
|
puts "We expected #{@arity} arguments and #{num_remaining} were provided."
|
136
136
|
exit
|
@@ -161,7 +161,8 @@ module Subcommander
|
|
161
161
|
|
162
162
|
private
|
163
163
|
def parse_args
|
164
|
-
@props[:
|
164
|
+
@props[:args] = @opts.parse(@args)
|
165
|
+
@props[:remaining_args] = @props[:args] # for legacy support
|
165
166
|
end
|
166
167
|
end
|
167
168
|
end
|
metadata
CHANGED
@@ -1,13 +1,12 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: subcommander
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash: 31
|
5
4
|
prerelease: false
|
6
5
|
segments:
|
7
6
|
- 1
|
7
|
+
- 1
|
8
8
|
- 0
|
9
|
-
|
10
|
-
version: 1.0.4
|
9
|
+
version: 1.1.0
|
11
10
|
platform: ruby
|
12
11
|
authors:
|
13
12
|
- Tom Santos
|
@@ -15,7 +14,7 @@ autorequire:
|
|
15
14
|
bindir: bin
|
16
15
|
cert_chain: []
|
17
16
|
|
18
|
-
date: 2011-
|
17
|
+
date: 2011-07-26 00:00:00 -07:00
|
19
18
|
default_executable:
|
20
19
|
dependencies: []
|
21
20
|
|
@@ -40,27 +39,23 @@ rdoc_options: []
|
|
40
39
|
require_paths:
|
41
40
|
- lib
|
42
41
|
required_ruby_version: !ruby/object:Gem::Requirement
|
43
|
-
none: false
|
44
42
|
requirements:
|
45
43
|
- - ">="
|
46
44
|
- !ruby/object:Gem::Version
|
47
|
-
hash: 3
|
48
45
|
segments:
|
49
46
|
- 0
|
50
47
|
version: "0"
|
51
48
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
52
|
-
none: false
|
53
49
|
requirements:
|
54
50
|
- - ">="
|
55
51
|
- !ruby/object:Gem::Version
|
56
|
-
hash: 3
|
57
52
|
segments:
|
58
53
|
- 0
|
59
54
|
version: "0"
|
60
55
|
requirements: []
|
61
56
|
|
62
57
|
rubyforge_project:
|
63
|
-
rubygems_version: 1.3.
|
58
|
+
rubygems_version: 1.3.6
|
64
59
|
signing_key:
|
65
60
|
specification_version: 3
|
66
61
|
summary: A library for cleanly handling subcommands (and options), like Git
|