Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/gambol99/options-dsl
Options DSL - small ruby dsl for defining command line options
https://github.com/gambol99/options-dsl
Last synced: 11 days ago
JSON representation
Options DSL - small ruby dsl for defining command line options
- Host: GitHub
- URL: https://github.com/gambol99/options-dsl
- Owner: gambol99
- Created: 2014-03-04T17:13:10.000Z (almost 11 years ago)
- Default Branch: master
- Last Pushed: 2014-11-11T21:32:27.000Z (about 10 years ago)
- Last Synced: 2024-04-17T15:10:31.351Z (9 months ago)
- Language: Ruby
- Size: 250 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
Options DSL
===========Notes: Still needs some work :-)
OptionsDSL is a library for defining command line options (albeit it could be used for other argument processing). The options, including global flags / switches and validation code can also be used to for subcommand; i.e. ./scipt.rb [options]
The DSL can been loaded from a single file or multiple files from a directory; The OptionsDSL class requires the following
config = {
:directory => '/my/directory/of/rules', # the full path to the directory,
:extensions => '*.ddl' # the regex to determine which file/s to read
:log_level => [nil,:info|:warn|:debug] # the logging level to employ
}
# the second argument can be used to pass some default options
dsl = OptionsDSL::new config, options | nilBelow is an example of the DSL language. Note, :global is a special command and effectly to used to describe all non subcommand options.
command :global, 'global and misc options' do
input :vagrant,
:description => 'the location of the vagrant executable',
:defaults => 'vagrant',
:validation => :executable,
:options => :vagrant,
:optional => false
input :vbox_manage,
:description => 'the location of the virtualbox manager tool',
:defaults => 'VBoxManage',
:validation => :executable,
:options => :vbox_manage,
:optional => false
input :classification,
:description => 'the location of the puppet classification file',
:defaults => 'puppet/classification.yaml',
:validation => :filename,
:options => :classification,
:optional => false
end
So to produce the following
./script subcommand1 -H hostname -d domainThe dsl would resemble
command :subcommand1, 'global and misc options' do
input :hostname,
:description => 'some description',
:validation => :string,
:options => :hostname,
:optional => false
input :domain,
:description => 'the domain',
:validation => :domain,
:options => :domain,
:optional => false
end
options :hostname,
:short => '-H hostname',
:long => '--hostname hostname'
options :domain,
:short => '-d domain',
:long => '--domain domain'
validation :hostname,
:format => :string,
:regex => /^[[:alpha:]\-]{,10}[0-9]{3}-[[:alnum:]]{2,5}$/
validation :domain
:format => :string,
:regex => /.*/