Class: Renogen::Cli::ParamParser

Inherits:
Object
  • Object
show all
Defined in:
lib/renogen/cli/param_parser.rb

Overview

Extracts options and version from argument list

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ ParamParser

Returns a new instance of ParamParser.



9
10
11
# File 'lib/renogen/cli/param_parser.rb', line 9

def initialize(options)
  @options = options
end

Instance Attribute Details

#optionsObject

Returns the value of attribute options.



7
8
9
# File 'lib/renogen/cli/param_parser.rb', line 7

def options
  @options
end

Instance Method Details

#parseHash

Extracts options and version from argument list

Returns:

  • (Hash)

    options



16
17
18
19
20
21
22
23
24
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
# File 'lib/renogen/cli/param_parser.rb', line 16

def parse
  args = Hash.new

  opt_parser = OptionParser.new do |opts|
    opts.banner =  "Usage:"
    opts.separator "    renogen [options] VERSION"
    opts.separator "    renogen new TICKET_NAME"
    opts.separator "    renogen init"
    opts.separator ""
    opts.separator "Required:"
    opts.separator "  VERSION      this is the version that is currently being required:"
    opts.separator "  TICKET_NAME  this is the name of the new ticket to be created:"
    opts.separator ""
    opts.separator "Options:"

    opts.on("-fFORMAT", "--format=FORMAT", "Output format to be generated") do |n|
      args['format'] = n
    end

    opts.on("-sSOURCE", "--source=SOURCE", "Type of source that changes will be extracted from") do |n|
      args['source'] = n
    end

    opts.on("-pPATH", "--path=PATH", "Path to changelog files") do |n|
      args['changelog_path'] = n
    end

    opts.on("-lVERSION", "--legacy=VERSION", "Used to collate all changes since") do |n|
      args['legacy_version'] = n
    end

    opts.on("-rDATE", "--release-date=DATE", "Release date") do |n|
      args['release_date'] = n
    end

    opts.on("-IPATH", "--include=PATH", "Add a path to the load path") do |n|
      $LOAD_PATH << n
    end

    opts.on("-RFILE", "--require=FILE", "Require a file from the load path") do |n|
      require n
    end

    opts.on_tail("-h", "--help", "Show this message") do
      puts opts
      exit
    end

    opts.on_tail("--version", "Show renogen version") do
      puts Renogen::VERSION
      exit
    end
  end

  opt_parser.parse!(options)

  new_version = options.shift
  if new_version.nil?
    puts "Error: Missing argument"
    puts
    puts opt_parser
    exit 1
  elsif options.count > 0
    puts "Error: Unknown arguments: #{options}"
    puts
    puts opt_parser
    exit 1
  end

  return new_version, args
end