Class: Enigma::CLI

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

Overview

A wrapper for command line interaction that encompasses option parsing, version, help and execution. This class is instantiated from the binary.

Usage:

cli = Enigma::CLI.new
cli.parse()

Constant Summary collapse

'usage: enigma [options] ...'.freeze

Instance Method Summary collapse

Constructor Details

#initialize(input: STDIN, output: STDOUT) ⇒ CLI

Returns a new instance of CLI.


16
17
18
19
20
# File 'lib/enigma/cli.rb', line 16

def initialize(input: STDIN, output: STDOUT)
  @machine = Machine.new
  @input = input
  @output = output
end

Instance Method Details

#parse(items = ARGV) ⇒ Object


22
23
24
25
26
27
28
29
30
31
# File 'lib/enigma/cli.rb', line 22

def parse(items = ARGV)
  Slop.parse(items) do |options|
    options.banner = BANNER

    options.on('-h', '--help', 'help') { return help(options) }
    options.on('-v', '--version', 'version') { return version }
  end

  execute
end