summaryrefslogtreecommitdiffstats
path: root/CLI/ruby
diff options
context:
space:
mode:
authora14m <[email protected]>2020-12-14 13:00:07 +0100
committera14m <[email protected]>2020-12-14 13:00:07 +0100
commit3265911ce64d7ee6a7f1ffc55ac3a4d132367604 (patch)
tree1483df4e0f4f9383394af3b5c3bdacaee9404352 /CLI/ruby
parent674a838588d3d1f8700bd1553b56b3e63c22db55 (diff)
Refactor the bin script to be simpler without any logic
Diffstat (limited to 'CLI/ruby')
-rwxr-xr-xCLI/ruby/bin/game-of-life26
1 files changed, 2 insertions, 24 deletions
diff --git a/CLI/ruby/bin/game-of-life b/CLI/ruby/bin/game-of-life
index f49682e..16dc0fa 100755
--- a/CLI/ruby/bin/game-of-life
+++ b/CLI/ruby/bin/game-of-life
@@ -3,7 +3,6 @@
require "game_of_life"
require "thor"
-require "io/console"
class CLI < Thor
map %w[-v --version] => :version
@@ -30,35 +29,14 @@ class CLI < Thor
desc: "Specify the dead-cell representation"
class_option "live-cell", type: :string, banner: :CHAR, default: "\u2588",
- desc: "Specify the dead-cell representation"
+ desc: "Specify the live-cell representation"
class_option "delay", aliases: "-d", type: :numeric, banner: "Milli-Seconds", default: 50,
desc: "Specify the introduced delay between each generation"
- # rubocop:disable Metrics/AbcSize
- # rubocop:disable Metrics/MethodLength
def start
- max_height = IO.console.winsize[0] - 2
- max_width = IO.console.winsize[1]
- if options["width"]&.> max_width
- fail GameOfLife::Error, "Invalid --width value, must not exceed current terminal width: #{max_width}"
- end
- if options["height"]&.> max_height
- fail GameOfLife::Error, "Invalid --height value, must not exceed current terminal height: #{max_height}"
- end
-
- options_with_console_defaults = {
- # Defaults the hight to less then the height of the terminal to allow banner info
- # and an extra emtpy line to avoid triggering terminal scroll while flushing
- "height" => max_height,
- "width" => max_width,
- "seed" => rand(100_000),
- }.merge(options)
-
- universe = GameOfLife.generate(options_with_console_defaults)
+ universe = GameOfLife.generate(GameOfLife.parsed_options(options))
GameOfLife.run(universe)
end
- # rubocop:enable Metrics/AbcSize
- # rubocop:enable Metrics/MethodLength
class << self
# Allow exit with status 1 on failure