It can be a huge pain to build arguments for an external service. There's all of those annoying escaping issues, and you just shouldn't have to deal with that crap.
Argh makes it easy to define how to serialize those attributes.
gem install argh
Just include Argh::Attributable
into any Ruby class, and you're off to
the races.
class Thing
include Argh::Attributable
argh 'command_attributes' do
attribute(:name)
attribute(:reverse_name) { name.reverse }
attribute(:direct, 'value')
end
private
def name
'Heyoo'
end
end
Thing.new.command_attributes # "-name 'Heyoo' -reverse_name 'ooyeH' -direct 'value'"
The default formatter is built to work
with and properly escape arguments for JCommander,
but it's very easy to add and use your own formatters (and contribute them). For an example,
check out the JCommanderFormatter
implementation. To use them, you can just pass a second argument to argh
,
like:
argh 'your_name', SomeOtherFormatter do
# ...
end
See LICENSE