clamp 1.1.1 → 1.1.2

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.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: efb289661d6e7a03227fbd5f87f3b39458743caa
4
- data.tar.gz: c8b16145accacae5bce4e23e5abec20b22f7379d
3
+ metadata.gz: b66f072d297e47ff393380b7507588265bfb147f
4
+ data.tar.gz: d4ab396390d9d8b850bcc74c39663bdd1f808a00
5
5
  SHA512:
6
- metadata.gz: 7d7faa3f545002d42539c7cdaf058d1990bbfd13094e27ddfae2aa4f73b1e5ce7b7a4804f304b97f885854c5c7a293a5ff4bbe1b7782906efdb673e4ddd435ca
7
- data.tar.gz: 3c51c2db6bcc0cd4a7797df94acc7cd24fe55845564a06a57843e1c8c3da9acb38ccb8171d0a21c1ff29c68faebcbfa8b453fa4b5abc33476d5be689e53ae253
6
+ metadata.gz: b37599b12abd509ef7d8f59e6267d624622d15ce34c7abf19c5669fc4d181dd418123aa567cfde22aae521db1363ba0022ca2a3ff4c17ef58823745f38e1d38e
7
+ data.tar.gz: 3f9e439caa164fec96a18ccabe438b6cc2f0edda1f7c09c76181c4f56b47c02b084995d36185ab2f702ec9bc0c81a5d1975e3ece7fb6b6f00b9d71273325c64e
data/CHANGES.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## 1.1.2 (2017-02-12)
4
+
5
+ * Improve usage help for commands with both parameters and subcommands.
6
+
3
7
  ## 1.1.1 (2016-10-19)
4
8
 
5
9
  * Rename `.declare_attribute` back to `.define_accessors_for`.
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- # An example of subcommands
3
+ # An example of options and parameters
4
4
 
5
5
  require "clamp"
6
6
 
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- # An example of subcommands
3
+ # An example of subcommands (including a default subcommand)
4
4
 
5
5
  require "clamp"
6
6
  require "clamp/version"
@@ -1,6 +1,6 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
- # An example of subcommands
3
+ # An example of nested subcommands
4
4
 
5
5
  require "clamp"
6
6
 
@@ -1,5 +1,7 @@
1
1
  #! /usr/bin/env ruby
2
2
 
3
+ # Demonstrate subcommand_missing
4
+
3
5
  require "clamp"
4
6
 
5
7
  Clamp do
@@ -0,0 +1,27 @@
1
+ #! /usr/bin/env ruby
2
+
3
+ # Demonstrate "restful" style; parameters precede subcommands
4
+
5
+ require "clamp"
6
+
7
+ Clamp do
8
+
9
+ banner %(
10
+ Word ops.
11
+ )
12
+
13
+ parameter "WORD", "the word in question"
14
+
15
+ subcommand "say", "Say it" do
16
+ def execute
17
+ puts word
18
+ end
19
+ end
20
+
21
+ subcommand "shout", "Say it loud" do
22
+ def execute
23
+ puts word.upcase
24
+ end
25
+ end
26
+
27
+ end
@@ -23,8 +23,6 @@ module Clamp
23
23
  end
24
24
  end
25
25
 
26
- protected
27
-
28
26
  def inheritable_parameters
29
27
  superclass_inheritable_parameters + parameters.select(&:inheritable?)
30
28
  end
@@ -15,7 +15,7 @@ module Clamp
15
15
 
16
16
  def instantiate_subcommand(name)
17
17
  subcommand_class = find_subcommand_class(name)
18
- subcommand = subcommand_class.new("#{invocation_path} #{name}", context)
18
+ subcommand = subcommand_class.new(invocation_path_for(name), context)
19
19
  self.class.inheritable_attributes.each do |attribute|
20
20
  next unless attribute.of(self).defined?
21
21
  attribute.of(subcommand).set(attribute.of(self).get)
@@ -23,6 +23,11 @@ module Clamp
23
23
  subcommand
24
24
  end
25
25
 
26
+ def invocation_path_for(name)
27
+ param_names = self.class.inheritable_parameters.map(&:name)
28
+ [invocation_path, *param_names, name].join(" ")
29
+ end
30
+
26
31
  def find_subcommand_class(name)
27
32
  subcommand_def = self.class.find_subcommand(name)
28
33
  return subcommand_def.subcommand_class if subcommand_def
@@ -1,3 +1,3 @@
1
1
  module Clamp
2
- VERSION = "1.1.1".freeze
2
+ VERSION = "1.1.2".freeze
3
3
  end
@@ -258,6 +258,14 @@ describe Clamp::Command do
258
258
  expect(stdout.strip).to eql "MONEY"
259
259
  end
260
260
 
261
+ it "shows parameter in usage help" do
262
+ begin
263
+ command.run(["stuff", "say", "--help"])
264
+ rescue Clamp::HelpWanted => e
265
+ expect(e.command.invocation_path).to eql("with THING say")
266
+ end
267
+ end
268
+
261
269
  end
262
270
 
263
271
  describe "each subcommand" do
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: 1.1.1
4
+ version: 1.1.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2016-10-19 00:00:00.000000000 Z
11
+ date: 2017-02-12 00:00:00.000000000 Z
12
12
  dependencies: []
13
13
  description: |
14
14
  Clamp provides an object-model for command-line utilities.
@@ -38,6 +38,7 @@ files:
38
38
  - examples/scoop
39
39
  - examples/speak
40
40
  - examples/subcommand_missing
41
+ - examples/word
41
42
  - lib/clamp.rb
42
43
  - lib/clamp/attribute/declaration.rb
43
44
  - lib/clamp/attribute/definition.rb
@@ -85,7 +86,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
85
86
  version: '0'
86
87
  requirements: []
87
88
  rubyforge_project:
88
- rubygems_version: 2.5.1
89
+ rubygems_version: 2.6.10
89
90
  signing_key:
90
91
  specification_version: 4
91
92
  summary: a minimal framework for command-line utilities