README.md in cri-2.3.0 vs README.md in cri-2.4.0
- old
+ new
@@ -18,16 +18,16 @@
usage 'dostuff [options]'
aliases :ds, :stuff
summary 'does stuff'
description 'This command does a lot of stuff. I really mean a lot.'
- flag :h, :help, 'show help for this command' do |value, cmd|
+ flag :h, :help, 'show help for this command' do |value, cmd|
puts cmd.help
exit 0
end
- flag :m, :more, 'do even more stuff'
- option :s, :stuff, 'specify stuff to do', :argument => :required
+ flag nil, :more, 'do even more stuff'
+ option :s, :stuff, 'specify stuff to do', :argument => :required
run do |opts, args, cmd|
stuff = opts[:stuff] || 'generic stuff'
puts "Doing #{stuff}!"
@@ -53,11 +53,11 @@
This command does a lot of stuff. I really mean a lot.
options:
-h --help show help for this command
- -m --more do even more stuff
+ --more do even more stuff
-s --stuff specify stuff to do
Let’s disect the command definition and start with the first five lines:
name 'dostuff'
@@ -74,24 +74,29 @@
Aliases don’t make sense for root commands, but for subcommands they do.
The next few lines contain the command’s option definitions:
- flag :h, :help, 'show help for this command' do |value, cmd|
+ flag :h, :help, 'show help for this command' do |value, cmd|
puts cmd.help
exit 0
end
- flag :m, :more, 'do even more stuff'
- option :s, :stuff, 'specify stuff to do', :argument => :required
+ flag nil, :more, 'do even more stuff'
+ option :s, :stuff, 'specify stuff to do', :argument => :required
Options can be defined using the following methods:
* {Cri::CommandDSL#option} or {Cri::CommandDSL#opt}
* {Cri::CommandDSL#flag} (implies forbidden argument)
* {Cri::CommandDSL#required} (implies required argument)
* {Cri::CommandDSL#optional} (implies optional argument)
+All these methods take the short option form as their first argument, and a
+long option form as their second argument. Either the short or the long form
+can be nil, but not both (because that would not make any sense). In the
+example above, the `--more` option has no short form.
+
Each of the above methods also take a block, which will be executed when the
option is found. The argument to the block are the option value (`true` in
case the option does not have an argument) and the command.
The last part of the command defines the execution itself:
@@ -123,12 +128,11 @@
root.cmd.add_command cmd_init
Contributors
------------
-(In alphabetical order)
-
* Toon Willems
+* Ken Coar
Thanks for Lee “injekt” Jarvis for [Slop][1], which has inspired the design of Cri 2.0.
[1]: https://github.com/injekt/slop