Class: Cukedep::CLI::CmdLine
- Inherits:
-
Object
- Object
- Cukedep::CLI::CmdLine
- Defined in:
- lib/cukedep/cli/cmd-line.rb
Overview
- Return the result of the command-line parsing
Instance Attribute Summary collapse
-
#options ⇒ Object
readonly
A Hash with the result of the command-line parse.
-
#parser ⇒ Object
readonly
OptionParser object.
Instance Method Summary collapse
-
#initialize ⇒ CmdLine
constructor
Constructor.
-
#parse!(theCmdLineArgs) ⇒ Object
Perform the command-line parsing.
Constructor Details
#initialize ⇒ CmdLine
Constructor.
25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 |
# File 'lib/cukedep/cli/cmd-line.rb', line 25 def initialize @options = {} @parser = OptionParser.new do |opts| opts. = <<-HELP Usage: cukedep [options] The command-line options are: HELP # No argument. Check dry_txt1 = 'Check the feature file dependencies' dry_txt2 = ' without running the feature files.' opts.on(nil, '--dry-run', dry_txt1 + dry_txt2) do [:dryrun] = true end # No argument. Create .cukedep.yml file setup_txt = 'Create a default .cukedep.yml file in current dir.' opts.on(nil, '--setup', setup_txt) do [:setup] = true end # Mandatory argument msg_p1 = 'Run the Cucumber project at given path ' msg_p2 = 'with features from current dir.' opts.on('--project PROJ_PATH', msg_p1 + msg_p2) do |project_path| [:project] = validated_project(project_path) end # No argument, shows at tail. This will print an options summary. opts.on_tail('-h', '--help', 'Show this message') do puts opts [:help] = true end opts.on_tail('--version', 'Show application version number') do puts Cukedep::Version [:version] = true end end end |
Instance Attribute Details
#options ⇒ Object (readonly)
A Hash with the result of the command-line parse.
19 20 21 |
# File 'lib/cukedep/cli/cmd-line.rb', line 19 def @options end |
#parser ⇒ Object (readonly)
OptionParser object
22 23 24 |
# File 'lib/cukedep/cli/cmd-line.rb', line 22 def parser @parser end |
Instance Method Details
#parse!(theCmdLineArgs) ⇒ Object
Perform the command-line parsing
68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 |
# File 'lib/cukedep/cli/cmd-line.rb', line 68 def parse!(theCmdLineArgs) begin parser.parse!(theCmdLineArgs) rescue OptionParser::MissingArgument => exc err_msg = '' exc.args.each do |arg| err_msg << "No argument provided with command line option: #{arg}\n" end err_msg << 'To see the command-line syntax, do:\ncukedep --help' raise StandardError, err_msg end # Some options stop the application exit if [:version] || [:help] return end |