Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Browse files

Merge branch 'master' of github.com:broadstreetads/argh

Conflicts:
	README.md
	lib/argh/collector.rb
	spec/examples/basic_spec.rb
  • Loading branch information...
commit ad44ff5100d5642a0ec2903ed440a091248e05df 2 parents fc3d22e + 4d518ef
@seejohnrun seejohnrun authored
View
3  README.md
@@ -26,6 +26,7 @@ class Thing
argh 'command_attributes' do
attribute(:name)
+ attribute(:proxy_name, :name)
attribute(:reverse_name) { name.reverse }
attribute(:direct, 'value')
end
@@ -38,7 +39,7 @@ class Thing
end
-Thing.new.command_attributes # "-name 'Heyoo' -reverse_name 'ooyeH' -direct 'value'"
+Thing.new.command_attributes # "-name 'Heyoo' -reverse_name 'ooyeH' -proxy_name 'Heyoo' -direct 'value'"
```
The default formatter is built to work
View
7 lib/argh/collector.rb
@@ -10,10 +10,15 @@ def initialize(&block)
end
def attribute(name, value = nil, &block)
+ attribute = nil
+ if value.is_a?(Symbol)
+ attribute = value
+ value = nil
+ end
@attributes << {
:name => name,
:value => value,
- :lambda => block || lambda { |i| i.send(name) }
+ :lambda => block || lambda { |i| i.send(attribute || name) }
}
end
View
10 lib/argh/formatters/base_formatter.rb
@@ -8,6 +8,12 @@ def initialize(collector, context)
@context = context
end
+ def process
+ raise 'BaseFormatter should be subclassed'
+ end
+
+ private
+
def attributes(&block)
return enum_for(:attributes) unless block_given?
@collector.attributes.each do |attr|
@@ -16,10 +22,6 @@ def attributes(&block)
end
end
- def process
- raise 'BaseFormatter should be subclassed'
- end
-
end
end
View
8 spec/examples/basic_spec.rb
@@ -27,6 +27,10 @@ class BasicExample
attribute(:name) { name.reverse }
end
+ argh 'symb' do
+ attribute(:the_name, :name)
+ end
+
private
def name
@@ -73,4 +77,8 @@ def age
example.straight.should == '-name \'john\''
end
+ it 'should be able to specify a symbol instead of a lambda' do
+ example.symb.should == '-the_name \'John Crepezzi\''
+ end
+
end
Please sign in to comment.
Something went wrong with that request. Please try again.