Class: Benry::CmdOpt::Facade

Inherits:
Object
  • Object
show all
Defined in:
lib/benry/cmdopt.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeFacade

Returns a new instance of Facade.



37
38
39
# File 'lib/benry/cmdopt.rb', line 37

def initialize()
  @schema = SCHEMA_CLASS.new
end

Instance Attribute Details

#schemaObject (readonly)

Returns the value of attribute schema.



41
42
43
# File 'lib/benry/cmdopt.rb', line 41

def schema
  @schema
end

Instance Method Details

#add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, multiple: nil, detail: nil, hidden: nil, important: nil, tag: nil, &callback) ⇒ Object



43
44
45
46
47
48
49
50
51
# File 'lib/benry/cmdopt.rb', line 43

def add(key, optdef, desc, *rest, type: nil, rexp: nil, pattern: nil, enum: nil, range: nil, value: nil, multiple: nil, detail: nil, hidden: nil, important: nil, tag: nil, &callback)
  rexp ||= pattern    # for backward compatibility
  #; [!vmb3r] defines command option.
  #; [!71cvg] type, rexp, enum, and range are can be passed as positional args as well as keyword args.
  @schema.add(key, optdef, desc, *rest,
              type: type, rexp: rexp, enum: enum, range: range, value: value, multiple: multiple, detail: detail, hidden: hidden, important: important, tag: tag, &callback)
  #; [!tu4k3] returns self.
  self
end

#each_option_and_desc(all: false, &block) ⇒ Object Also known as: each_option_help



61
62
63
64
65
66
67
68
# File 'lib/benry/cmdopt.rb', line 61

def each_option_and_desc(all: false, &block)
  #; [!wght5] returns enumerator object if block not given.
  return @schema.each_option_and_desc(all: all) unless block_given?()
  #; [!bw9qx] yields each option definition string and help message.
  #; [!kunfw] yields all items (including hidden items) if `all: true` specified.
  @schema.each_option_and_desc(all: all, &block)
  self
end

#option_help(width_or_format = nil, all: false) ⇒ Object Also known as: to_s



53
54
55
56
# File 'lib/benry/cmdopt.rb', line 53

def option_help(width_or_format=nil, all: false)
  #; [!dm4p8] returns option help message.
  return @schema.option_help(width_or_format, all: all)
end

#parse(argv, all: true, &error_handler) ⇒ Object



71
72
73
74
75
76
77
78
79
# File 'lib/benry/cmdopt.rb', line 71

def parse(argv, all: true, &error_handler)
  #; [!7gc2m] parses command options.
  #; [!no4xu] returns option values as dict.
  #; [!areof] handles only OptionError when block given.
  #; [!peuva] returns nil when OptionError handled.
  #; [!za9at] parses options only before args when `all: false`.
  parser = PARSER_CLASS.new(@schema)
  return parser.parse(argv, all: all, &error_handler)
end