Class: Bhook::ArgsParser

Inherits:
Object
  • Object
show all
Extended by:
T::Sig
Defined in:
lib/bhook/args_parser.rb

Defined Under Namespace

Classes: Options

Instance Method Summary collapse

Constructor Details

#initialize(argv) ⇒ ArgsParser

Returns a new instance of ArgsParser.



10
11
12
13
14
# File 'lib/bhook/args_parser.rb', line 10

def initialize(argv)
  @args = Options.new(nil, nil, false, false, Bhook::THEME_DIR_PATH, nil, false, nil, false)
  @argv = argv.clone
  @opt_parser = build_opt_parser
end

Instance Method Details

#help_textObject



34
35
36
# File 'lib/bhook/args_parser.rb', line 34

def help_text
  @opt_parser.to_s
end

#parseObject



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/bhook/args_parser.rb', line 16

def parse
  if (mount = detect_and_read_mount_args_from_config_in_pwd)
    @args.mount = mount
  end

  begin
    @opt_parser.parse(@argv)
    if generate_theme_missing? && help_missing? &&
       source_or_output_paths_missing? && mount_config_missing?
      raise OptionParser::MissingArgument, 'See --help.'
    end
  rescue OptionParser::ParseError => e
    puts "\nError! #{e.message}\n"
    return nil
  end
  @args
end