module TheGame::CLI
TheGame::CLI
is the_game's command-line interface.
The executable the_game
calls this method. Here is the source of the_game
:
require 'the_game' require 'the_game/cli' TheGame::CLI.start!(ARGV)
Public Class Methods
start!(args = ARGV)
click to toggle source
# File lib/the_game/cli.rb, line 9 def start!(args = ARGV) @game = TheGame::Game.new @game_mode = nil opts = OptionParser.new(args) do |opts| opts.banner = "Usage: the_game [options] [mode]" opts.separator '' opts.separator 'Options' opts.on("-n", "--name NAME", "Set character's name to NAME.") { |n| @game.name = n } opts.separator 'Modes' opts.on("-p", "--play", "Play the game") { @game_mode = :play } opts.on("-h", "--help", "Display this message and exit") opts.on("-l", "--license", "Display license and exit") { @game_mode = :license } opts.on("-v", "--version", "Display version and exit") { @game_mode = :version } end opts.parse! case @game_mode when :play then @game.start! when :license then puts TheGame::LICENSE when :version then puts "the_game v#{TheGame::Version::STRING}" else puts opts end # Display help message end