Class: Jobim::CLI

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

Overview

Command line interface for the Jobim application. Utilizes optparse to manage user arguments and populates a ‘Jobim::Settings` object.

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#exitObject (readonly)

Returns the value of attribute exit.



6
7
8
# File 'lib/jobim/cli.rb', line 6

def exit
  @exit
end

#optionsHash (readonly)

Memoized, lazy accessor for the options hash.

Returns:

  • (Hash)

    options generated from #parse



18
19
20
# File 'lib/jobim/cli.rb', line 18

def options
  @options
end

#parserOptionParser (readonly)

Memoized accessor for the ‘OptionParser` object. It is generated only when called upon. See the readme for information about the command flags.

Returns:

  • (OptionParser)


34
35
36
# File 'lib/jobim/cli.rb', line 34

def parser
  @parser
end

#settingsJobim::Settings (readonly)

Memoized, lazy accessor for the settings object.

Returns:



11
12
13
# File 'lib/jobim/cli.rb', line 11

def settings
  @settings
end

Instance Method Details

#helpString

Help documentation of the program.

Returns:

  • (String)


105
106
107
# File 'lib/jobim/cli.rb', line 105

def help
  parser.to_s
end

#parse(args) ⇒ NilClass

Runs the parse method of the value returned by the ‘#parser` method. This is done in a manner destructive to the passed args `Array`. If there is a trailing value after parsing is completed it is treated as the `:dir` option.

Parameters:

  • args (Array<String>)

    to be paresed

Returns:

  • (NilClass)

    sentitinal nil value



95
96
97
98
99
100
# File 'lib/jobim/cli.rb', line 95

def parse(args)
  parser.parse!(args)
  options[:dir] = File.expand_path(args[0]) if args.length == 1

  nil
end