From ec3a936b360797f04d646c8c4737a5f6704113fb Mon Sep 17 00:00:00 2001 From: Denis Knauf Date: Sun, 13 Dec 2020 17:06:00 +0100 Subject: [PATCH] example added. bugfixes. .gitignore --- .gitignore | 8 ++++++++ bin/example.rb | 25 +++++++++++++++++++++++++ lib/dencli.rb | 2 +- 3 files changed, 34 insertions(+), 1 deletion(-) create mode 100644 .gitignore create mode 100755 bin/example.rb diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..9106b2a --- /dev/null +++ b/.gitignore @@ -0,0 +1,8 @@ +/.bundle/ +/.yardoc +/_yardoc/ +/coverage/ +/doc/ +/pkg/ +/spec/reports/ +/tmp/ diff --git a/bin/example.rb b/bin/example.rb new file mode 100755 index 0000000..c898258 --- /dev/null +++ b/bin/example.rb @@ -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 diff --git a/lib/dencli.rb b/lib/dencli.rb index 5238723..745bdbb 100755 --- a/lib/dencli.rb +++ b/lib/dencli.rb @@ -124,7 +124,7 @@ class DenCli def _add name, min, obj, aliases name = name.to_s unless name.nil? @subs[name] = obj - CL.gen_aliases( name, min) {|a| @aliases[a] = obj } + DenCli.gen_aliases( name, min) {|a| @aliases[a] = obj } if aliases [*aliases].each {|a| @aliases[a] = obj } end