Class: Cukedep::CLI::CmdLine

Inherits:
Object
  • Object
show all
Defined in:
lib/cukedep/cli/cmd-line.rb

Overview

  • Return the result of the command-line parsing

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCmdLine

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.banner = <<-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
      options[: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
      options[: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|
      options[: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
      options[:help] = true
    end

    opts.on_tail('--version', 'Show application version number') do
      puts Cukedep::Version
      options[:version] = true
    end
  end
end

Instance Attribute Details

#optionsObject (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
  @options
end

#parserObject (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 options[:version] || options[:help]

  return options
end