diff options
Diffstat (limited to 'CLI/ruby')
| -rwxr-xr-x | CLI/ruby/bin/game-of-life | 43 | ||||
| -rw-r--r-- | CLI/ruby/lib/game_of_life.rb | 1 |
2 files changed, 44 insertions, 0 deletions
diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life index 4d62bac..8abd1e0 100755 --- a/CLI/ruby/bin/game-of-life +++ b/CLI/ruby/bin/game-of-life @@ -2,3 +2,46 @@ # frozen_string_literal: true require "game_of_life" +require "thor" +require "io/console" + +class CLI < Thor + map %w[-v --version] => :version + desc "--version, -v", "Prints the Game of Life version information" + def version + puts "Game of Life version #{GameOfLife::VERSION}" + end + + default_task :start + desc "start [OPTIONS]", "Start the Game of Life simulations" + class_option "seed", aliases: "-s", type: :numeric, banner: :SEED, + desc: "Specify the seed number to use as an initial state (default to random)." + + class_option "input", aliases: "-i", type: :string, banner: :VALUE, + desc: "Specify the path/URL for the file to use as an initial state. (used instead of seed)" + + class_option "width", aliases: "-w", type: :numeric, banner: :WIDTH, + desc: "Specify the width of generated universe. (default to terminal width)" + + class_option "height", aliases: "-h", type: :numeric, banner: :HEIGHT, + desc: "Specify the hight of generated universe. (default to terminal height)" + def start + options_with_defaults = { + "height" => IO.console.winsize[0], + "width" => IO.console.winsize[1], + "seed" => rand(100_000), + }.merge(options) + + GameOfLife::Universe.new(options_with_defaults).run + end + + class << self + # Allow exit with status 1 on failure + # Ref: https://github.com/erikhuda/thor/issues/244#issue-6116190 + def exit_on_failure? + true + end + end +end + +CLI.start(ARGV) diff --git a/CLI/ruby/lib/game_of_life.rb b/CLI/ruby/lib/game_of_life.rb index 4cff146..33bbb74 100644 --- a/CLI/ruby/lib/game_of_life.rb +++ b/CLI/ruby/lib/game_of_life.rb @@ -1,6 +1,7 @@ # frozen_string_literal: true require "game_of_life/version" +require "game_of_life/universe" module GameOfLife class Error < StandardError; end |
