Class: MxxRu::Generators::BinaryUnittest::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/generators/bin-unittest/g.rb

Overview

Class for storing command-line arguments as options.

Usage:

options = Options.parse( args, banner )

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#output_fileObject

Name of output file (-o, –output-file). nil if missing.



53
54
55
# File 'lib/mxx_ru/generators/bin-unittest/g.rb', line 53

def output_file
  @output_file
end

#project_pathObject

Project path (name of project directory in cmd-line). nil if missing.



51
52
53
# File 'lib/mxx_ru/generators/bin-unittest/g.rb', line 51

def project_path
  @project_path
end

Class Method Details

.parse(args, banner) ⇒ Object

Parsing command-line arguments and returning Options instance.

Calls exit(1) if –help present in args.



59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
# File 'lib/mxx_ru/generators/bin-unittest/g.rb', line 59

def Options.parse( args, banner )
  parser = OptionParser.new

  result = Options.new

  parser.banner = banner

  parser.on( '-o', '--output-file FILE', 'Output file name' ) do |p|
    result.output_file = p
  end

  parser.on_tail( '-h', '--help', 'Show this message' ) do
    puts parser
    exit(1)
  end

  parser.order!( args ) do |noarg|
    # Any non-options is considered as project path name.
    result.project_path = noarg
  end

  result
end