Module: AlacrittyThemes::Parser
- Defined in:
- lib/alacritty_themes/parser.rb
Overview
Arguments parser
Class Method Summary collapse
- .add_banner ⇒ Object
- .add_create_option(options) ⇒ Object
- .add_help_option(options) ⇒ Object
- .add_version_option(options) ⇒ Object
- .from(argv) ⇒ Object
- .parser ⇒ Object
Class Method Details
.add_banner ⇒ Object
49 50 51 |
# File 'lib/alacritty_themes/parser.rb', line 49 def parser. = "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() parser.on("-c", "--create", "Creates file") do [:command] = :create [: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() parser.on("-h", "--help", "Shows help") do [:command] = :help [: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() parser.on("-v", "--version", "Shows version") do [:command] = :version [: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) = {} [:parser] = parser add_create_option() add_version_option() add_help_option() parser.parse!(argv) rescue OptionParser::ParseError => e { command: :error, message: e. } end |
.parser ⇒ Object
24 25 26 |
# File 'lib/alacritty_themes/parser.rb', line 24 def parser @parser ||= OptionParser.new end |