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 |
# File 'lib/mongify/cli/options.rb', line 18 def progname = @parser.program_name return <<EOB Usage: #{progname} command [database_translation.rb] [-c database.config] Commands: #{Mongify::CLI::WorkerCommand.list_commands.join("\n")} Examples: #{progname} check -c database.config #{progname} translation -c datbase.config > database_translation.rb #{progname} process database_translation.rb -c database.config 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
54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mongify/cli/options.rb', line 54 def parse if @command_class == HelpCommand HelpCommand.new(@parser) elsif @command_class == VersionCommand VersionCommand.new(@parser.program_name) else raise ConfigurationFileNotFound, "You need to provide a configuration file location #{@config_file}" unless @config_file #TODO: In the future, request sql_connection and nosql_connection from user input config = Configuration.parse(@config_file) WorkerCommand.new(action, config, translation_file, @parser) end end |
#set_options ⇒ Object
Sets the options for CLI Also used for help output
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'lib/mongify/cli/options.rb', line 39 def @parser. = @parser.separator "Common options:" @parser.on("-h", "--help", "Show this message") do @command_class = HelpCommand end @parser.on("-v", "--version", "Show version") do @command_class = VersionCommand end @parser.on('-c', '--config FILE', "Configuration File to use") do |file| @config_file = file end end |