clamp 0.6.4 → 0.6.5

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0222cf7a03642506d668988d57a60b992accc073
4
- data.tar.gz: 9d0314d698965b297003ebca1ad6a31183c91fac
3
+ metadata.gz: c8d58bd5db9ac6b414b75d34a947149720909757
4
+ data.tar.gz: d61add398880941423c32234e2e9c1d57a1c38f3
5
5
  SHA512:
6
- metadata.gz: c9cbcdeded12d74963a8a00681f715640d185f6a0ee6faa285cf9b03b8f00721115a35664602f06b2ea40e8fd670be3546338f624b24feae7d450f1a659ad9e0
7
- data.tar.gz: 4d304f351b33bd4eeb034837b3174d06898dd02eb5349db2142be751634b5885b0bc2160654b7af3a97392582fcab705968c2b7de72b37bb1828b885eef6c76e
6
+ metadata.gz: 7df1c2418b54a047af268ca936cabc828ecc2ac2f24bb9ca7a0b8a83768dd9b03679178d61ae79b18cd5a932626c5ae5da3d98d353d8517f2f668b00f4971cb4
7
+ data.tar.gz: 9298c454fd95f1ad91e4a852fabf51bc0ebb3b915c6164a0f2e012625b2ed1a8e170244c376ec6a54580583c471d3b7a0bd1cab45d5ac1a0437bc739989b819a
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 0.6.5 (2015-05-02)
4
+
5
+ * Catch signals and exit appropriately.
6
+
3
7
  ## 0.6.4 (2015-02-26)
4
8
 
5
9
  * Ensure computed defaults are only computed once.
@@ -140,6 +140,8 @@ module Clamp
140
140
  rescue Clamp::ExecutionError => e
141
141
  $stderr.puts "ERROR: #{e.message}"
142
142
  exit(e.status)
143
+ rescue SignalException => e
144
+ exit(128 + e.signo)
143
145
  end
144
146
  end
145
147
 
@@ -35,6 +35,16 @@ module Clamp
35
35
  recognised_subcommands.find { |sc| sc.is_called?(name) }
36
36
  end
37
37
 
38
+ def find_subcommand_class(*names)
39
+ names.inject(self) do |command_class, name|
40
+ if command_class
41
+ if subcommand = command_class.find_subcommand(name)
42
+ subcommand.subcommand_class
43
+ end
44
+ end
45
+ end
46
+ end
47
+
38
48
  def parameters_before_subcommand
39
49
  parameters.take_while { |p| p != @subcommand_parameter }
40
50
  end
@@ -1,3 +1,3 @@
1
1
  module Clamp
2
- VERSION = "0.6.4".freeze
2
+ VERSION = "0.6.5".freeze
3
3
  end
@@ -66,6 +66,15 @@ describe Clamp::Command do
66
66
 
67
67
  end
68
68
 
69
+ describe ".find_subcommand_class" do
70
+
71
+ it "finds subcommand classes" do
72
+ flip_class = command_class.find_subcommand_class("flip")
73
+ expect(flip_class.new("xx").message).to eq("FLIPPED")
74
+ end
75
+
76
+ end
77
+
69
78
  end
70
79
 
71
80
  context "with an aliased subcommand" do
@@ -112,9 +121,14 @@ describe Clamp::Command do
112
121
  subcommand "foo", "Foo!" do
113
122
 
114
123
  subcommand "bar", "Baaaa!" do
124
+
125
+ def self.this_is_bar
126
+ end
127
+
115
128
  def execute
116
129
  puts "FUBAR"
117
130
  end
131
+
118
132
  end
119
133
 
120
134
  end
@@ -126,6 +140,14 @@ describe Clamp::Command do
126
140
  expect(stdout).to match /FUBAR/
127
141
  end
128
142
 
143
+ describe ".find_subcommand_class" do
144
+
145
+ it "finds nested subcommands" do
146
+ expect(command_class.find_subcommand_class("foo", "bar")).to respond_to(:this_is_bar)
147
+ end
148
+
149
+ end
150
+
129
151
  end
130
152
 
131
153
  context "with a default subcommand" do
@@ -37,8 +37,11 @@ end
37
37
  module CommandFactory
38
38
 
39
39
  def given_command(name, &block)
40
+ let(:command_class) do
41
+ Class.new(Clamp::Command, &block)
42
+ end
40
43
  let(:command) do
41
- Class.new(Clamp::Command, &block).new(name)
44
+ command_class.new(name)
42
45
  end
43
46
  end
44
47
 
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: clamp
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.6.4
4
+ version: 0.6.5
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-02-26 00:00:00.000000000 Z
11
+ date: 2015-05-02 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Clamp provides an object-model for command-line utilities.