26 lines
1 KiB
Ruby
Executable file
26 lines
1 KiB
Ruby
Executable file
#!/usr/bin/env ruby
|
|
|
|
require 'dencli'
|
|
|
|
cli = DenCli.new 'example', "This is an example for generate a DenCli-API"
|
|
cli.cmd( :example, "I have an example command") { STDERR.puts "This is an example" }
|
|
cli.cmd( :help, "", aliases: [nil, '-h', '--help']) {|*args| STDERR.puts cli.help(*args) }
|
|
|
|
cli.sub( :more, "Sub-Commands are also possible with a new cli") do |sub|
|
|
sub.cmd( :help, "") {|*args| STDERR.puts cli.help( 'more', *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.sub( :deeper, "You want to have Sub-Sub-Commands?") do |sub2|
|
|
sub2.cmd( :help, "") {|*args| STDERR.puts cli.help( 'more', 'deeper', *args) }
|
|
sub2.cmd( :last, "The last example") { STDERR.puts "The last example" }
|
|
|
|
sub2.sub( :'sub-commands', "Endless Sub-Sub- ...") do |sub3|
|
|
sub2.cmd( :help, "") {|*args| STDERR.puts cli.help( 'more', 'deeper', 'sub-commands', *args) }
|
|
sub3.cmd( :hehe, "The real last example", min: 2) { STDERR.puts "Trust me!" }
|
|
end
|
|
end
|
|
end
|
|
|
|
cli.call *ARGV
|