Module: AlacrittyThemes::Parser

Defined in:
lib/alacritty_themes/parser.rb

Overview

Arguments parser

Class Method Summary collapse

Class Method Details

.add_bannerObject



49
50
51
# File 'lib/alacritty_themes/parser.rb', line 49

def add_banner
  parser.banner = "Usage: alacritty_themes [options]"
end

.add_create_option(options) ⇒ Object



28
29
30
31
32
33
# File 'lib/alacritty_themes/parser.rb', line 28

def add_create_option(options)
  parser.on("-c", "--create", "Creates file") do
    options[:command] = :create
    options[:message] = "alacritty.yml was created"
  end
end

.add_help_option(options) ⇒ Object



42
43
44
45
46
47
# File 'lib/alacritty_themes/parser.rb', line 42

def add_help_option(options)
  parser.on("-h", "--help", "Shows help") do
    options[:command] = :help
    options[:message] = parser.help
  end
end

.add_version_option(options) ⇒ Object



35
36
37
38
39
40
# File 'lib/alacritty_themes/parser.rb', line 35

def add_version_option(options)
  parser.on("-v", "--version", "Shows version") do
    options[:command] = :version
    options[:message] = "Alacritty Themes v#{AlacrittyThemes::VERSION}"
  end
end

.from(argv) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
22
# File 'lib/alacritty_themes/parser.rb', line 9

def from(argv)
  options = {}

  options[:parser] = parser
  add_banner
  add_create_option(options)
  add_version_option(options)
  add_help_option(options)
  parser.parse!(argv)

  options
rescue OptionParser::ParseError => e
  { command: :error, message: e.message }
end

.parserObject



24
25
26
# File 'lib/alacritty_themes/parser.rb', line 24

def parser
  @parser ||= OptionParser.new
end