clamp 0.4.0 → 0.5.0

Sign up to get free protection for your applications and to get access to all the features.
data/lib/clamp/command.rb CHANGED
@@ -71,11 +71,7 @@ module Clamp
71
71
  # This method is designed to be overridden in sub-classes.
72
72
  #
73
73
  def execute
74
- if @subcommand
75
- @subcommand.execute
76
- else
77
- raise "you need to define #execute"
78
- end
74
+ raise "you need to define #execute"
79
75
  end
80
76
 
81
77
  # @return [String] usage documentation for this command
@@ -0,0 +1,20 @@
1
+ module Clamp
2
+ class Subcommand
3
+
4
+ module Execution
5
+
6
+ # override default Command behaviour
7
+
8
+ def execute
9
+ # delegate to subcommand
10
+ @subcommand.run(remaining_arguments)
11
+ end
12
+
13
+ def handle_remaining_arguments
14
+ # no-op, because subcommand will handle them
15
+ end
16
+
17
+ end
18
+
19
+ end
20
+ end
@@ -1,3 +1,5 @@
1
+ require 'clamp/subcommand/execution'
2
+
1
3
  module Clamp
2
4
  class Subcommand
3
5
 
@@ -9,8 +11,7 @@ module Clamp
9
11
  return false unless self.class.has_subcommands?
10
12
  subcommand_name = parse_subcommand_name
11
13
  @subcommand = instatiate_subcommand(subcommand_name)
12
- @subcommand.parse(remaining_arguments)
13
- remaining_arguments.clear
14
+ self.extend(Subcommand::Execution)
14
15
  end
15
16
 
16
17
  private
data/lib/clamp/version.rb CHANGED
@@ -1,3 +1,3 @@
1
1
  module Clamp
2
- VERSION = "0.4.0".freeze
2
+ VERSION = "0.5.0".freeze
3
3
  end
@@ -9,15 +9,19 @@ describe Clamp::Command do
9
9
 
10
10
  given_command "flipflop" do
11
11
 
12
+ def execute
13
+ puts message
14
+ end
15
+
12
16
  subcommand "flip", "flip it" do
13
- def execute
14
- puts "FLIPPED"
17
+ def message
18
+ "FLIPPED"
15
19
  end
16
20
  end
17
21
 
18
22
  subcommand "flop", "flop it\nfor extra flop" do
19
- def execute
20
- puts "FLOPPED"
23
+ def message
24
+ "FLOPPED"
21
25
  end
22
26
  end
23
27
 
@@ -43,20 +47,6 @@ describe Clamp::Command do
43
47
 
44
48
  end
45
49
 
46
- describe "#parse" do
47
-
48
- describe "with too many arguments" do
49
-
50
- it "raises a UsageError" do
51
- lambda do
52
- @command.parse(["flip", "extra", "args"])
53
- end.should raise_error(Clamp::UsageError, "too many arguments")
54
- end
55
-
56
- end
57
-
58
- end
59
-
60
50
  describe "#help" do
61
51
 
62
52
  it "shows subcommand parameters in usage" do
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.4.0
4
+ version: 0.5.0
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-05-13 00:00:00.000000000 Z
12
+ date: 2012-10-17 00:00:00.000000000 Z
13
13
  dependencies: []
14
14
  description: ! "Clamp provides an object-model for command-line utilities. \nIt handles
15
15
  parsing of command-line options, and generation of usage help.\n"
@@ -43,6 +43,7 @@ files:
43
43
  - lib/clamp/parameter/parsing.rb
44
44
  - lib/clamp/subcommand.rb
45
45
  - lib/clamp/subcommand/declaration.rb
46
+ - lib/clamp/subcommand/execution.rb
46
47
  - lib/clamp/subcommand/parsing.rb
47
48
  - lib/clamp/version.rb
48
49
  - spec/clamp/command_group_spec.rb
@@ -65,7 +66,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
65
66
  version: '0'
66
67
  segments:
67
68
  - 0
68
- hash: -1903818616036317857
69
+ hash: 1042041036949173101
69
70
  required_rubygems_version: !ruby/object:Gem::Requirement
70
71
  none: false
71
72
  requirements:
@@ -74,10 +75,10 @@ required_rubygems_version: !ruby/object:Gem::Requirement
74
75
  version: '0'
75
76
  segments:
76
77
  - 0
77
- hash: -1903818616036317857
78
+ hash: 1042041036949173101
78
79
  requirements: []
79
80
  rubyforge_project:
80
- rubygems_version: 1.8.21
81
+ rubygems_version: 1.8.23
81
82
  signing_key:
82
83
  specification_version: 3
83
84
  summary: a minimal framework for command-line utilities