Class: Gruesome::CLI

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

Constant Summary collapse

<<-USAGE
Usage:
  gruesome play STORY_FILE

Description:
  The 'play' command will start a session of the story given as STORY_FILE

Example:
  gruesome play zork1.z3

USAGE

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.parse_optionsObject



22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
# File 'lib/gruesome/cli.rb', line 22

def parse_options
  @opts = OptionParser.new do |opts|
    opts.banner = BANNER.gsub(/^    /, '')

    opts.separator ''
    opts.separator 'Options:'

    opts.on('-h', '--help', 'Display this help') do
      puts opts
      exit
    end
  end

  @opts.parse!
end

.runObject



38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
# File 'lib/gruesome/cli.rb', line 38

def CLI.run
  begin
    parse_options
  rescue OptionParser::InvalidOption => e
    warn e
    exit -1
  end

  def fail
    puts @opts
    exit -1
  end

  if ARGV.empty?
    fail
  end

  case ARGV.first
  when 'play'
    fail unless ARGV[1]

    Gruesome::Logo.display

    puts
    puts "--------------------------------------------------------------------------------"
    puts

    Gruesome::Machine.new(ARGV[1]).execute
  end
end

Instance Method Details

#failObject



46
47
48
49
# File 'lib/gruesome/cli.rb', line 46

def fail
  puts @opts
  exit -1
end