Class: CreateGithubRelease::CommandLine::Parser

Inherits:
Object
  • Object
show all
Defined in:
lib/create_github_release/command_line/parser.rb

Overview

Parses the options for this script

Examples:

Specify the release type

options = CommandLineParser.new.parse('major')
options.valid? # => true
options.release_type # => "major"
options.quiet # => false

Specify the release type and the quiet option

parser = CommandLineParser.new
args = %w[minor --quiet]
options = parser.parse(*args)
options.release_type # => "minor"
options.quiet # => true

Show the command line help

CommandLineParser.new.parse('--help')
parser.parse('--help')

Instance Method Summary collapse

Constructor Details

#initializeParser

Create a new command line parser

Examples:

parser = CommandLineParser.new


39
40
41
42
43
# File 'lib/create_github_release/command_line/parser.rb', line 39

def initialize
  @option_parser = OptionParser.new
  define_options
  @options = CreateGithubRelease::CommandLine::Options.new
end

Instance Method Details

#parse(*args) ⇒ CreateGithubRelease::CommandLine::Options

Parse the command line arguements returning the options

Examples:

parser = CommandLineParser.new
options = parser.parse(['major'])

Parameters:

  • args (Array<String>)

    the command line arguments

Returns:



55
56
57
58
59
60
61
62
63
64
65
# File 'lib/create_github_release/command_line/parser.rb', line 55

def parse(*args)
  begin
    option_parser.parse!(remaining_args = args.dup)
  rescue OptionParser::InvalidOption, OptionParser::MissingArgument => e
    report_errors(e.message)
  end
  parse_remaining_args(remaining_args)
  # puts options unless options.quiet
  report_errors(*options.errors) unless options.valid?
  options
end