Skip to content

Latest commit

 

History

History
59 lines (41 loc) · 1.31 KB

README.md

File metadata and controls

59 lines (41 loc) · 1.31 KB

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(: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

License

See LICENSE