Module: TTY::Option::Interface

Defined in:
lib/tty/option.rb

Instance Method Summary collapse

Instance Method Details

#help(**config, &block) ⇒ String

Provide a formatted help usage for the configured parameters

Returns:

  • (String)


63
64
65
# File 'lib/tty/option.rb', line 63

def help(**config, &block)
  Formatter.help(self.class.parameters, self.class.usage, **config, &block)
end

#paramsObject

The parsed parameters



37
38
39
# File 'lib/tty/option.rb', line 37

def params
  @__params ||= Params.create
end

#parse(argv = ARGV, env = ENV, check_invalid_params: true, raise_on_parse_error: false) ⇒ Object

Parse command line arguments

Parameters:

  • argv (Array<String>) (defaults to: ARGV)

    the command line arguments

  • env (Hash) (defaults to: ENV)

    the hash of environment variables



49
50
51
52
53
54
55
56
# File 'lib/tty/option.rb', line 49

def parse(argv = ARGV, env = ENV, check_invalid_params: true,
          raise_on_parse_error: false)
  parser = Parser.new(self.class.parameters,
                      check_invalid_params: check_invalid_params,
                      raise_on_parse_error: raise_on_parse_error)
  @__params = Params.create(*parser.parse(argv, env))
  self
end