@ -95,7 +95,62 @@ class Capture
end
end
cli . cmd ( :args , " Expects and prints given arguments " ,
& lambda { | a , b , c : , d : , e : , f : , g : |
p a : a , b : b , c : c , d : d , e : e
} ) .
opt ( :c , '-c=ForC' , " Option c " ) .
opt ( :d , '-dForD' , " Option d " , default : " something " ) .
opt ( :e , '-e' , " Toggle e " , default : false ) .
opt ( :f , '--[no-]f' , " Toggle f " , default : false ) .
opt ( :g , '--long-option=sth' , " Long option, no short option " , default : " nothing " ) .
opt ( :h , '-hsth' , " No long option, only short option " , default : " nothing " )
cli . cmd ( :example , " I have an example command " ) { $stderr . puts " This is an example " }
cli . cmd ( :help , " An example for help " , aliases : [ nil , '-h' , '--help' ] , & lambda { | * commands , full : |
if full
cli . help_full * commands , output : $stderr
else
cli . help * commands , output : $stderr
end
} ) .
opt ( :full , '-f' , '--[no-]full' , " Print all commands and sub-commands. " , default : false )
cli . sub ( :more , " Sub-Commands are also possible with a new cli " ) do | sub |
sub . cmd ( :help , " " , aliases : [ nil , '-h' , '--help' ] ) { | * args | $stderr . puts sub . help ( * args ) }
sub . cmd ( :example , " Here is an example, too " ) { $stderr . puts " This is an other example " }
sub . cmd ( :foo , " BAR " ) { $stderr . puts " FOO bar " }
sub . cmd ( :args , " Expects and prints given arguments " , & lambda { | a , b = 1 , c : , d : 5 , e : |
p a : a , b : b , c : c , d : d , e : e
} ) .
opt ( :c , '-c=ForC' , " Option c " ) .
opt ( :d , '-d=ForD' , " Option d (implicit default) " ) .
opt ( :e , '-e' , " Toggle e " )
sub . sub ( :deeper , " You want to have Sub-Sub-Commands? " ) do | sub2 |
sub2 . cmd ( :help , " " , aliases : [ nil , '-h' , '--help' ] , & lambda { | * commands | sub2 . help ( * commands , output : $stderr ) } )
sub2 . cmd ( :last , " The last example " , & lambda { $stderr . puts " The last example " } )
sub2 . sub ( :'sub-commands' , " Endless Sub-Sub- ... with a special alias " ) do | sub3 |
# h -> help
# he -> hehe
# hel -> help
# help -> help
# heh -> hehe
# hehe -> hehe
sub3 . cmd ( :help , " " , min : 3 , aliases : [ nil , :h ] ) { | * args | $stderr . puts sub3 . help ( * args ) }
sub3 . cmd ( :hehe , " The real last example " , min : 2 ) { $stderr . puts " Trust me! " }
end
end
end
cli . cmd ( :cli , " Interactive shell " , min : 3 , & lambda { ||
cli . interactive ( File . basename ( $0 , '.rb' ) ) . run
} )
cli . sub :tests , " Some tests " , noshortaliases : true do | tcli |
tcli . cmd ( :help , " " , min : 4 ) { | * args | $stderr . puts tcli . help ( * args ) }
OptionParser . accept IPAddr do | arg |
begin
IPAddr . new arg
@ -202,50 +257,6 @@ cli.sub :tests, "Some tests", noshortaliases: true do |tcli|
end . opt ( :verbose , '-v' , 'Prints additional information per test' , default : false )
end
cli . cmd ( :args , " Expects and prints given arguments " ,
& lambda { | a , b , c : , d : , e : , f : , g : |
p a : a , b : b , c : c , d : d , e : e
} ) .
opt ( :c , '-c=ForC' , " Option c " ) .
opt ( :d , '-dForD' , " Option d " , default : " something " ) .
opt ( :e , '-e' , " Toggle e " , default : false ) .
opt ( :f , '--[no-]f' , " Toggle f " , default : false ) .
opt ( :g , '--long-option=sth' , " Long option, no short option " , default : " nothing " ) .
opt ( :h , '-hsth' , " No long option, only short option " , default : " nothing " )
cli . cmd ( :example , " I have an example command " ) { $stderr . puts " This is an example " }
cli . cmd ( :help , " An example for help " , aliases : [ nil , '-h' , '--help' ] , & lambda { | * commands , full : |
if full
cli . help_full * commands , output : $stderr
else
cli . help * commands , output : $stderr
end
} ) .
opt ( :full , '-f' , '--[no-]full' , " Print all commands and sub-commands. " , default : false )
cli . sub ( :more , " Sub-Commands are also possible with a new cli " ) do | sub |
sub . cmd ( :help , " " , aliases : [ nil , '-h' , '--help' ] ) { | * args | $stderr . puts sub . help ( * args ) }
sub . cmd ( :example , " Here is an example, too " ) { $stderr . puts " This is an other example " }
sub . cmd ( :foo , " BAR " ) { $stderr . puts " FOO bar " }
sub . cmd ( :args , " Expects and prints given arguments " , & lambda { | a , b = 1 , c : , d : 5 , e : |
p a : a , b : b , c : c , d : d , e : e
} ) .
opt ( :c , '-c=ForC' , " Option c " ) .
opt ( :d , '-d=ForD' , " Option d (implicit default) " ) .
opt ( :e , '-e' , " Toggle e " )
sub . sub ( :deeper , " You want to have Sub-Sub-Commands? " ) do | sub2 |
sub2 . cmd ( :help , " " , aliases : [ nil , '-h' , '--help' ] , & lambda { | * commands | sub2 . help ( * commands , output : $stderr ) } )
sub2 . cmd ( :last , " The last example " , & lambda { $stderr . puts " The last example " } )
sub2 . sub ( :'sub-commands' , " Endless Sub-Sub- ... " ) do | sub3 |
sub3 . cmd ( :help , " " ) { | * args | $stderr . puts sub3 . help ( sub3 , * args ) }
sub3 . cmd ( :hehe , " The real last example " , min : 2 ) { $stderr . puts " Trust me! " }
end
end
end
begin
cli . call * ARGV
rescue DenCli :: UsageError