example added. bugfixes. .gitignore

This commit is contained in:
Denis Knauf 2020-12-13 17:06:00 +01:00
parent fb9a9898ee
commit ec3a936b36
3 changed files with 34 additions and 1 deletions

8
.gitignore vendored Normal file
View file

@ -0,0 +1,8 @@
/.bundle/
/.yardoc
/_yardoc/
/coverage/
/doc/
/pkg/
/spec/reports/
/tmp/

25
bin/example.rb Executable file
View file

@ -0,0 +1,25 @@
#!/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

View file

@ -124,7 +124,7 @@ class DenCli
def _add name, min, obj, aliases def _add name, min, obj, aliases
name = name.to_s unless name.nil? name = name.to_s unless name.nil?
@subs[name] = obj @subs[name] = obj
CL.gen_aliases( name, min) {|a| @aliases[a] = obj } DenCli.gen_aliases( name, min) {|a| @aliases[a] = obj }
if aliases if aliases
[*aliases].each {|a| @aliases[a] = obj } [*aliases].each {|a| @aliases[a] = obj }
end end