Class: MxxRu::Generators::Impl::Cpp::Options

Inherits:
Object
  • Object
show all
Defined in:
lib/mxx_ru/generators/impl/cpp/generation.rb

Overview

Class for storing command-line arguments as options.

Usage:

options = Options.parse( args, banner, { :implib_path => false } )

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Attribute Details

#implib_pathObject

Name of import library path (–implib-path).



70
71
72
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 70

def implib_path
  @implib_path
end

#output_fileObject

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



72
73
74
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 72

def output_file
  @output_file
end

#project_pathObject

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



68
69
70
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 68

def project_path
  @project_path
end

#target_nameObject

Name of target (-t, –target).



66
67
68
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 66

def target_name
  @target_name
end

Class Method Details

.parse(args, banner, params) ⇒ Object

Parsing command-line arguments and returning Options instance.

These keys are supported in params:

implib_path

true or false. Enables/disables argument –implib-path.

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



81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
# File 'lib/mxx_ru/generators/impl/cpp/generation.rb', line 81

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

  result = Options.new

  parser.banner = banner

  parser.on( '-t', '--target NAME', 'Target name' ) do |p|
    result.target_name = p
  end

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

  if true == params.fetch( :implib_path, false ) 
    parser.on( '--implib-path PATH', 'Import library path name' ) do |p|
      result.implib_path = p
    end
  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