Class: Mongify::CLI::Options
- Inherits:
-
Object
- Object
- Mongify::CLI::Options
- Defined in:
- lib/mongify/cli/options.rb
Overview
Used to parse the options for an application
Instance Method Summary collapse
-
#banner ⇒ Object
Banner for help output.
-
#initialize(argv) ⇒ Options
constructor
A new instance of Options.
-
#parse ⇒ Object
Parses CLI passed attributes and figures out what command user is trying to run.
-
#set_options ⇒ Object
Sets the options for CLI Also used for help output.
Constructor Details
#initialize(argv) ⇒ Options
Returns a new instance of Options.
8 9 10 11 12 13 14 15 |
# File 'lib/mongify/cli/options.rb', line 8 def initialize(argv) @parsed = false @argv = argv @parser = OptionParser.new #@command_class = ReekCommand end |
Instance Method Details
#banner ⇒ Object
Banner for help output
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/mongify/cli/options.rb', line 18 def progname = @parser.program_name return <<EOB Usage: #{progname} command database.config [database_translation.rb] Commands: #{Mongify::CLI::Command::Worker.list_commands.join("\n")} Examples: #{progname} check database.config #{progname} translation datbase.config > database_translation.rb #{progname} process database.config database_translation.rb #{progname} sync database.config database_translation.rb See http://github.com/anlek/mongify for more details EOB end |
#parse ⇒ Object
Parses CLI passed attributes and figures out what command user is trying to run
52 53 54 55 56 57 58 59 60 |
# File 'lib/mongify/cli/options.rb', line 52 def parse if @command_class == Command::Help Command::Help.new(@parser) elsif @command_class == Command::Version Command::Version.new(@parser.program_name) else Command::Worker.new(action, config_file, translation_file, @parser) end end |
#set_options ⇒ Object
Sets the options for CLI Also used for help output
40 41 42 43 44 45 46 47 48 49 |
# File 'lib/mongify/cli/options.rb', line 40 def @parser. = @parser.separator "Common options:" @parser.on("-h", "--help", "Show this message") do @command_class = Command::Help end @parser.on("-v", "--version", "Show version") do @command_class = Command::Version end end |