Class: Inch::CLI::Command::Options::Base Abstract

Inherits:
Object
  • Object
show all
Includes:
TraceHelper, YardoptsHelper
Defined in:
lib/inch/cli/command/options/base.rb

Overview

This class is abstract.

Subclass and override #set_options

Abstract base class for CLI options. Provides some helper methods for the option parser.

Direct Known Subclasses

BaseList, BaseObject

Constant Summary

Constants included from YardoptsHelper

YardoptsHelper::VALID_YARD_SWITCHES

Instance Attribute Summary

Attributes included from YardoptsHelper

#excluded, #yard_files

Class Method Summary collapse

Instance Method Summary collapse

Methods included from YardoptsHelper

#parse_yardopts_options, #yardopts_options

Methods included from TraceHelper

#ui

Class Method Details

.attribute(name, default = nil) ⇒ void

This method returns an undefined value.

Creates an attribute with an optional default value

Parameters:

  • name (Symbol)

    the name of the attribute

  • default (nil) (defaults to: nil)

    the default value of the attribute



29
30
31
32
33
34
35
36
# File 'lib/inch/cli/command/options/base.rb', line 29

def attribute(name, default = nil)
  define_method(name) do
    instance_variable_get("@#{name}") || default
  end
  define_method("#{name}=") do |value|
    instance_variable_set("@#{name}", value)
  end
end

Instance Method Details

#parse(args) ⇒ void

This method returns an undefined value.

Parses the given args “into” the current Options object

Parameters:

  • args (Array<String>)

    command-line arguments



47
48
49
50
51
52
53
54
55
56
57
# File 'lib/inch/cli/command/options/base.rb', line 47

def parse(args)
  opts = OptionParser.new
  opts.banner = usage

  descriptions.each do |text|
    opts.separator "  " + text
  end

  set_options(opts)
  parse_options(opts, args)
end

#set_options(opts) ⇒ void

Note:

Override to fill with individual options

This method returns an undefined value.

Sets all options for the current Options object

Parameters:

  • opts (OptionParser)


65
66
67
# File 'lib/inch/cli/command/options/base.rb', line 65

def set_options(opts)
  common_options(opts)
end

#verifyvoid

Note:

Override to fill with validations

This method returns an undefined value.

Verifies if the given options are valid



74
75
# File 'lib/inch/cli/command/options/base.rb', line 74

def verify
end