clamp 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/examples/fubar +23 -0
- data/lib/clamp/subcommand/declaration.rb +2 -1
- data/lib/clamp/version.rb +1 -1
- data/spec/clamp/command_group_spec.rb +23 -0
- metadata +5 -4
data/examples/fubar
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
#! /usr/bin/env ruby
|
2
|
+
|
3
|
+
# An example of subcommands
|
4
|
+
|
5
|
+
require "clamp"
|
6
|
+
|
7
|
+
class Fubar < Clamp::Command
|
8
|
+
|
9
|
+
subcommand "foo", "Foo!" do
|
10
|
+
|
11
|
+
subcommand "bar", "Baaaa!" do
|
12
|
+
|
13
|
+
def execute
|
14
|
+
puts "FUBAR"
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
Fubar.run
|
@@ -30,9 +30,10 @@ module Clamp
|
|
30
30
|
end
|
31
31
|
|
32
32
|
def has_subcommands!
|
33
|
-
unless
|
33
|
+
unless @has_subcommands
|
34
34
|
parameter "SUBCOMMAND", "subcommand name", :attribute_name => :subcommand_name
|
35
35
|
parameter "[ARGS] ...", "subcommand arguments", :attribute_name => :subcommand_arguments
|
36
|
+
@has_subcommands = true
|
36
37
|
end
|
37
38
|
end
|
38
39
|
|
data/lib/clamp/version.rb
CHANGED
@@ -52,6 +52,29 @@ describe Clamp::Command do
|
|
52
52
|
|
53
53
|
end
|
54
54
|
|
55
|
+
describe "with nested subcommands" do
|
56
|
+
|
57
|
+
given_command "fubar" do
|
58
|
+
|
59
|
+
subcommand "foo", "Foo!" do
|
60
|
+
|
61
|
+
subcommand "bar", "Baaaa!" do
|
62
|
+
def execute
|
63
|
+
puts "FUBAR"
|
64
|
+
end
|
65
|
+
end
|
66
|
+
|
67
|
+
end
|
68
|
+
|
69
|
+
end
|
70
|
+
|
71
|
+
it "delegates multiple levels" do
|
72
|
+
@command.run(["foo", "bar"])
|
73
|
+
stdout.should =~ /FUBAR/
|
74
|
+
end
|
75
|
+
|
76
|
+
end
|
77
|
+
|
55
78
|
describe "each subcommand" do
|
56
79
|
|
57
80
|
before do
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: clamp
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 31
|
5
5
|
prerelease: false
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 2
|
10
|
+
version: 0.1.2
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- Mike Williams
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2010-11-
|
18
|
+
date: 2010-11-22 00:00:00 +11:00
|
19
19
|
default_executable:
|
20
20
|
dependencies: []
|
21
21
|
|
@@ -37,6 +37,7 @@ files:
|
|
37
37
|
- Rakefile
|
38
38
|
- clamp.gemspec
|
39
39
|
- examples/flipflop
|
40
|
+
- examples/fubar
|
40
41
|
- examples/speak
|
41
42
|
- lib/clamp.rb
|
42
43
|
- lib/clamp/attribute_declaration.rb
|