Skip to content

broadstreetads/argh

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

27 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

About

Easy argument building in Ruby

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages