Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Easy argument building in Ruby
Ruby
tree: ad44ff5100

Fetching latest commit…

Cannot retrieve the latest commit at this time

Failed to load latest commit information.
lib
spec
.gitignore
.travis.yml
Gemfile
LICENSE
README.md
Rakefile
argh.gemspec

README.md

argh

Build Status

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.

Installation

gem install argh

Usage

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(:proxy_name, :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' -proxy_name 'Heyoo' -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

License

See LICENSE

Something went wrong with that request. Please try again.