Class: Helmsnap::ArgsParser

Inherits:
Object
  • Object
show all
Defined in:
lib/helmsnap/args_parser.rb

Defined Under Namespace

Classes: Args

Constant Summary collapse

InvalidConfigPath =
Class.new(RuntimeError)
DEFAULT_CONFIG_PATH =
Pathname.new(".helmsnap.yaml")
CONFIG_PATH_HELP =
%{Path to config (default: "#{DEFAULT_CONFIG_PATH}")}.freeze
"Usage: helmsnap CMD [options]"

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ArgsParser

Returns a new instance of ArgsParser.



12
13
14
15
16
# File 'lib/helmsnap/args_parser.rb', line 12

def initialize(options)
  self.options = options
  self.args = Args.new(DEFAULT_CONFIG_PATH)
  self.parser = build_parser
end

Instance Method Details

#get_options!Object



18
19
20
21
22
23
# File 'lib/helmsnap/args_parser.rb', line 18

def get_options!
  parser.parse!(options)
  args
rescue OptionParser::ParseError, InvalidConfigPath => error
  print_help!(error.message)
end


25
26
27
28
29
# File 'lib/helmsnap/args_parser.rb', line 25

def print_help!(msg)
  Helmsnap::Console.error($stderr, "#{msg}\n") if msg
  Helmsnap::Console.print($stdout, parser.help)
  exit 1
end