Class: GithubCLI::Command::Arguments

Inherits:
Object
  • Object
show all
Defined in:
lib/github_cli/command/arguments.rb

Overview

Makes it easy to parse required and options arguments.

Constant Summary collapse

SEPARATOR =
'/'

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args) ⇒ Arguments

Returns a new instance of Arguments


12
13
14
# File 'lib/github_cli/command/arguments.rb', line 12

def initialize(args)
  @args = args
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args


10
11
12
# File 'lib/github_cli/command/arguments.rb', line 10

def args
  @args
end

Instance Method Details

#inspectObject

Returns a concise string representation of Arguments instance


31
32
33
# File 'lib/github_cli/command/arguments.rb', line 31

def inspect
  "#<#{self.class.inspect} @args=#{args.inspect}"
end

#parseObject

Returns seperated arguments


17
18
19
20
21
22
23
24
25
26
27
# File 'lib/github_cli/command/arguments.rb', line 17

def parse
  required, non_required = nil, nil

  if !args.empty?
    required = args
    non_required, required = required.split('/', 2) if required.index('/')
  else
    raise RequiredArgumentMissingError, "No value provided for required argument"
  end
  [non_required, required]
end