class DenCli

Constants

VERSION

Attributes

subs[R]

Public Class Methods

g(cmd, min = nil)
Alias for: gen_aliases
gen_aliases(cmd, min = nil) { |cmd| ... } click to toggle source

Generates a list of aliases for given `cmd`: `g(:abc)` => `[“a”, “ab”, “abc”]` `g(:abcdef, 4)` => `[“abcd”, “abcde”, “abcdef”]`

# File lib/dencli.rb, line 46
def gen_aliases cmd, min = nil
        r = ((min||1)-1).upto cmd.length-1
        if block_given?
                r.each {|i| yield cmd[0..i] }
        else
                r.map  {|i| cmd[0..i] }
        end
end
Also aliased as: g
n(s, min = nil) click to toggle source

Helper Function for generate Regular Expressions of string, which matches all strings which has parts fron beginning of the given string. `n(“abc”)` would produce: `/(?:a|ab|abc)/` You can define a minimum length to match: `n(“abcdef”,4)` => `/abcd(?:|e|ef)/`

# File lib/dencli.rb, line 20
def n s, min = nil
        min ||= 1
        /#{s.length <= min ?
                Regexp.quote(s) :
                "#{Regexp.quote s[0...min]}#{
                        s[min...-1].
                                reverse.
                                each_char.
                                reduce( "#{Regexp.quote s[-1]}?") {|f,n|
                                        "(?:#{Regexp.quote n}#{f})?"
                        }
                }"
        }/
end
new(progname, description) click to toggle source
# File lib/dencli.rb, line 59
def initialize progname, description
        @subs = Sub.new self, progname, description
end
r(s, min = nil) click to toggle source

Wraps `n(s,min=)` in a full matching RegExp with ending `0`: `r(“abc”)` would produce: `/A(?:a|ab|abc)0z/` You can define a minimum length to match: `r(“abcdef”,4)` => `/aabcd(?:|e|ef)0z/`

# File lib/dencli.rb, line 39
def r s, min = nil
        /\A#{n s, min}\0\z/
end

Public Instance Methods

[](k) click to toggle source
# File lib/dencli.rb, line 87
def [] k
        @subs[k]
end
_full_cmd(post) click to toggle source
# File lib/dencli.rb, line 67
def _full_cmd post
        post
end
call(*a) click to toggle source
# File lib/dencli.rb, line 79
def call *a
        @subs.call *a
end
cmd(*a, &exe) click to toggle source
# File lib/dencli.rb, line 75
def cmd *a, &exe
        @subs.cmd *a, &exe
end
full_cmd() click to toggle source
# File lib/dencli.rb, line 63
def full_cmd
        []
end
help(*args) click to toggle source
# File lib/dencli.rb, line 83
def help *args
        @subs.help *args
end
interactive(*args, **opts) click to toggle source
# File lib/dencli.rb, line 91
def interactive *args, **opts
        Interactive.new self, *args, **opts
end
sub(*a, &exe) click to toggle source
# File lib/dencli.rb, line 71
def sub *a, &exe
        @subs.sub *a, &exe
end