Class: Islo::CLI

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

Overview

Handle and run the command line interface

Constant Summary collapse

NAME =
File.basename($PROGRAM_NAME)
RC =

See sysexits(3)

{ ok:           0,
error:        1,
usage:       64,
data:        65,
noinput:     66,
nouser:      67,
nohost:      68,
unavailable: 69,
software:    70,
oserr:       71,
osfile:      72,
cantcreat:   73,
ioerr:       74,
tempfail:    75,
protocol:    76,
noperm:      77,
config:      78 }

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(args = ARGV) ⇒ CLI

Returns a new instance of CLI.



40
41
42
43
44
45
46
# File 'lib/islo/cli.rb', line 40

def initialize(args = ARGV)
  @args, @opts = parse(args)
rescue Slop::InvalidOptionError => e
  die(:usage, e.message)
rescue Slop::MissingArgumentError => e
  die(:usage, e.message)
end

Instance Attribute Details

#argsObject (readonly)

Returns the value of attribute args.



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

def args
  @args
end

Class Method Details

.startObject

Shortcut for Islo::CLI.new.start



30
31
32
# File 'lib/islo/cli.rb', line 30

def self.start
  new.start
end

Instance Method Details

#optsObject



36
37
38
# File 'lib/islo/cli.rb', line 36

def opts
  @opts.to_hash
end

#startObject

Start execution based on options



49
50
51
52
53
# File 'lib/islo/cli.rb', line 49

def start
  Islo.command(args, title: opts[:title]).exec
rescue Islo::Command::Error => e
  die(:oserr, e.message)
end