Skip to content

Commit

Permalink
Update README
Browse files Browse the repository at this point in the history
  • Loading branch information
sshaw committed Jan 24, 2015
1 parent 7843b4f commit 182de58
Showing 1 changed file with 20 additions and 19 deletions.
39 changes: 20 additions & 19 deletions README.rdoc
@@ -1,6 +1,6 @@
= Optout

Optout helps you write code that will call +exec+ and +system+ like functions. It allows you to map hash keys to command line
Optout helps you write code that will call +exec+ and +system+ like functions. It allows you to map hash keys to command line
arguments and define validation rules that must be met before the command line arguments are created.

== Overview
Expand All @@ -20,7 +20,7 @@ arguments and define validation rules that must be met before the command line a
:gem => "rake",
:os => "mswin",
:version => "0.9.2",
:user => truep
:user => truep
}

exec "gem", *optout.argv(options)
Expand All @@ -37,38 +37,38 @@ arguments and define validation rules that must be met before the command line a

Inorder to turn the incoming option hash into something useful you must tell +Optout+ a bit about your options. This is done by calling <code>Optout#on</code> and passing it the name of a key in the option hash. The simplest case is an option with no switch:

optout = Optout.options do
optout = Optout.options do
on :path
end

optout.shell(:path => "/home/sshaw")
# Returns: '/home/sshaw'

Key names can be a +Symbol+ or a +String+, +Optout+ will check for both in the option hash.
Key names can be a +Symbol+ or a +String+, +Optout+ will check for both in the option hash.

If the option has a switch it can be given after the option's key:

optout = Optout.options do
optout = Optout.options do
on :path, "-p"
end

optout.shell(:path => "/home/sshaw")
# Returns: -p '/home/sshaw'

Some programs can be finicky about the space between the switch and the value, or require options
Some programs can be finicky about the space between the switch and the value, or require options
in a different format. +Optout+ accepts various configuration options that can remdy this:

optout = Optout.options do
optout = Optout.options do
on :path, "-p", :arg_separator => ""
end

optout.shell(:path => "/home/sshaw")
# Returns: -p'/home/sshaw'

optout = Optout.options do
optout = Optout.options do
on :path, "--path", :arg_separator => "=", :required => true
end

optout.shell(:path => "/home/sshaw")
# Returns: --path='/home/sshaw'

Expand All @@ -77,41 +77,41 @@ in a different format. +Optout+ accepts various configuration options that can r

Options can be grouped into required and optional:

Optout.options :arg_separator => "=" do
required do
Optout.options :arg_separator => "=" do
required do
on :in, "if"
on :out, "of"
end

optional do
optional do
on :size, "size"
on :count, "count"
end
end

optout.shell(:in => "/dev/zero", :out => "/var/log/secure")
# Returns: in='/dev/zero' out='/var/log/secure'

== Validating Options

+Optout+ can validate your options too. Just specify the validation rule after the option's key or switch:

optout = Optout.options do
optout = Optout.options do
# Must match [a-z]
on :path, "-p", /[a-z]/
end

optout = Optout.options do
optout = Optout.options do
# Must be true, false, or nil (add :required => true to allow only true or false)
on :path, "-p", Optout::Boolean
end

optout = Optout.options do
optout = Optout.options do
# Must be in the given set
on :path, %w(/home/sshaw /Users/gatinha /Users/fofinha)
end

optout = Optout.options do
optout = Optout.options do
# Must be a diretory under "/home" and have user read and write permissions
on :path, Optout::Dir.under("/home").permissions("rw")
end
Expand All @@ -121,15 +121,16 @@ Options can be grouped into required and optional:

== TODOs

* Proper <code>cmd.exe</code> quoting
* Proper <code>cmd.exe</code> quoting
* Mutually exclusive options
* Split options i.e., <code>:jvm => %w[A B C]</code> would be created as <code>-XA -XB -XC</code>
* Validate based on the presence of other options

== More Info

=== RDoc

http://rubydoc.info/github/sshaw/optout/frames (with RDoc -> YARD incompatibilities :)
http://www.ruby-doc.org/gems/docs/o/optout-0.0.2

=== Bugs

Expand Down

0 comments on commit 182de58

Please sign in to comment.