Class: Benry::CmdApp::ActionMetadata

Inherits:
BaseMetadata show all
Defined in:
lib/benry/cmdapp.rb

Instance Attribute Summary collapse

Attributes inherited from BaseMetadata

#desc, #hidden, #important, #name, #tag

Instance Method Summary collapse

Constructor Details

#initialize(name, desc, schema, klass, meth, usage: nil, detail: nil, description: nil, postamble: nil, tag: nil, important: nil, hidden: nil) ⇒ ActionMetadata

Returns a new instance of ActionMetadata.



271
272
273
274
275
276
277
278
279
280
# File 'lib/benry/cmdapp.rb', line 271

def initialize(name, desc, schema, klass, meth, usage: nil, detail: nil, description: nil, postamble: nil, tag: nil, important: nil, hidden: nil)
  super(name, desc, tag: tag, important: important, hidden: hidden)
  @schema    = schema
  @klass     = klass
  @meth      = meth
  @usage     = usage       if nil != usage
  @detail    = detail      if nil != detail
  @description = description if nil != description
  @postamble = postamble   if nil != postamble
end

Instance Attribute Details

#descriptionObject (readonly)

Returns the value of attribute description.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def description
  @description
end

#detailObject (readonly)

Returns the value of attribute detail.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def detail
  @detail
end

#klassObject (readonly)

Returns the value of attribute klass.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def klass
  @klass
end

#methObject (readonly)

Returns the value of attribute meth.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def meth
  @meth
end

#postambleObject (readonly)

Returns the value of attribute postamble.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def postamble
  @postamble
end

#schemaObject (readonly)

Returns the value of attribute schema.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def schema
  @schema
end

#usageObject (readonly)

Returns the value of attribute usage.



282
283
284
# File 'lib/benry/cmdapp.rb', line 282

def usage
  @usage
end

Instance Method Details

#alias?Boolean

Returns:

  • (Boolean)


311
312
313
314
# File 'lib/benry/cmdapp.rb', line 311

def alias?()
  #; [!c1eq3] returns false which means that this is not an alias metadata.
  return false
end

#hidden?Boolean

Returns:

  • (Boolean)


284
285
286
287
288
289
# File 'lib/benry/cmdapp.rb', line 284

def hidden?()
  #; [!stied] returns true/false if `hidden:` kwarg provided.
  #; [!eumhz] returns true/false if method is private or not.
  return @hidden if @hidden != nil
  return ! @klass.method_defined?(@meth)
end

#option_empty?(all: false) ⇒ Boolean

Returns:

  • (Boolean)


291
292
293
294
295
296
# File 'lib/benry/cmdapp.rb', line 291

def option_empty?(all: false)
  #; [!14xgg] returns true if the action has no options.
  #; [!dbtht] returns false if the action has at least one option.
  #; [!wa315] considers hidden options if `all: true` passed.
  return @schema.empty?(all: all)
end

#option_help(format, all: false) ⇒ Object



298
299
300
301
302
# File 'lib/benry/cmdapp.rb', line 298

def option_help(format, all: false)
  #; [!bpkwn] returns help message string of the action.
  #; [!76hni] includes hidden options in help message if `all:` is truthy.
  return @schema.option_help(format, all: all)
end

#parse_options(args) ⇒ Object



304
305
306
307
308
309
# File 'lib/benry/cmdapp.rb', line 304

def parse_options(args)
  #; [!gilca] returns parsed options.
  #; [!v34yk] raises OptionError if option has error.
  parser = ACTION_OPTION_PARSER_CLASS.new(@schema)
  return parser.parse(args, all: true)  # raises error if invalid option given
end