From 660be09d6fe42309cbf112290e1715a30afd5d50 Mon Sep 17 00:00:00 2001 From: Samuel Williams Date: Fri, 7 Jul 2017 01:25:18 +1200 Subject: [PATCH] Fix Command#[] --- lib/samovar/command.rb | 10 ++++------ spec/samovar/command_spec.rb | 15 ++++++++++++--- 2 files changed, 16 insertions(+), 9 deletions(-) diff --git a/lib/samovar/command.rb b/lib/samovar/command.rb index a8c380e..0c621d1 100644 --- a/lib/samovar/command.rb +++ b/lib/samovar/command.rb @@ -51,6 +51,10 @@ def [](*input) self.dup.tap{|command| command.parse(input)} end + def parse(input) + self.class.table.parse(input, self) + end + def initialize(input = nil) parse(input) if input end @@ -118,11 +122,5 @@ def print_usage(*args, output: $stderr, formatter: Output::DetailedFormatter) formatter.print(rows, output) end - - private - - def parse(input) - self.class.table.parse(input, self) - end end end diff --git a/spec/samovar/command_spec.rb b/spec/samovar/command_spec.rb index bbb531b..2c7625a 100644 --- a/spec/samovar/command_spec.rb +++ b/spec/samovar/command_spec.rb @@ -28,12 +28,21 @@ class Top < Samovar::Command RSpec.describe Samovar::Command do it "should use default value" do - top = Top.parse([]) + top = Top[] expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION' end + it "can update options" do + top = Top[] + expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION' + + top = top['--verbose'] + expect(top.options[:configuration]).to be == 'TEAPOT_CONFIGURATION' + expect(top.options[:logging]).to be == :verbose + end + it "should parse a simple command" do - top = Top.parse(["-c", "path", "bottom", "foobar", "A", "B", "--", "args", "args"]) + top = Top["-c", "path", "bottom", "foobar", "A", "B", "--", "args", "args"] expect(top.options[:configuration]).to be == 'path' expect(top.command.class).to be == Bottom @@ -43,7 +52,7 @@ class Top < Samovar::Command end it "should generate documentation" do - top = Top.new([]) + top = Top[] buffer = StringIO.new top.print_usage('top', output: buffer)