Skip to content

Commit

Permalink
Fix Command#[]
Browse files Browse the repository at this point in the history
  • Loading branch information
ioquatix committed Jul 6, 2017
1 parent 70a2537 commit 660be09
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 9 deletions.
10 changes: 4 additions & 6 deletions lib/samovar/command.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -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
15 changes: 12 additions & 3 deletions spec/samovar/command_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand All @@ -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)

Expand Down

0 comments on commit 660be09

Please sign in to comment.