Permalink
Browse files

Allow symbol specification of attributes

  • Loading branch information...
1 parent e27ac90 commit 4a3c4686ae4739a69d159e8502eeadf2db96305c @seejohnrun seejohnrun committed Oct 31, 2012
Showing with 12 additions and 3 deletions.
  1. +2 −1 README.md
  2. +2 −2 lib/argh/collector.rb
  3. +8 −0 spec/examples/basic_spec.rb
View
@@ -26,6 +26,7 @@ class Thing
argh 'command_attributes' do
attribute(:name)
+ attribute(:proxy_name, :name)
attribute(:reverse_name) { name.reverse }
end
@@ -37,7 +38,7 @@ class Thing
end
-Thing.new.command_attributes # "-name 'Heyoo' -reverse_name 'ooyeH'"
+Thing.new.command_attributes # "-name 'Heyoo' -reverse_name 'ooyeH' -proxy_name 'Heyoo'"
```
The default formatter is built to work
View
@@ -9,10 +9,10 @@ def initialize(&block)
instance_eval(&block)
end
- def attribute(name, &block)
+ def attribute(name, attribute = nil, &block)
@attributes << {
:name => name,
- :lambda => block || lambda { |i| i.send(name) }
+ :lambda => block || lambda { |i| i.send(attribute || name) }
}
end
@@ -23,6 +23,10 @@ class BasicExample
attribute(:name) { name.reverse }
end
+ argh 'symb' do
+ attribute(:the_name, :name)
+ end
+
private
def name
@@ -65,4 +69,8 @@ def age
example.lambs.should == '-name \'izzeperC nhoJ\''
end
+ it 'should be able to specify a symbol instead of a lambda' do
+ example.symb.should == '-the_name \'John Crepezzi\''
+ end
+
end

0 comments on commit 4a3c468

Please sign in to comment.