-
-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Better handling of defaults in parser.
- Loading branch information
Showing
13 changed files
with
140 additions
and
81 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -19,5 +19,5 @@ | |
# THE SOFTWARE. | ||
|
||
module Samovar | ||
VERSION = "1.5.0" | ||
VERSION = "1.6.0" | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
|
||
require 'samovar' | ||
require 'stringio' | ||
|
||
module Samovar::CoerceSpec | ||
class Coerce < Samovar::Command | ||
options do | ||
option '--things <array>', "A list of things" do |input| | ||
input.split(/\s*,\s*/) | ||
end | ||
|
||
option '--count <integer>', "A number to count", type: Integer | ||
end | ||
end | ||
|
||
RSpec.describe Samovar::Command do | ||
it "should coerce to array" do | ||
top = Coerce['--things', 'a,b,c'] | ||
expect(top.options[:things]).to be == ['a', 'b', 'c'] | ||
end | ||
|
||
it "should coerce to integer" do | ||
top = Coerce['--count', '10'] | ||
expect(top.options[:count]).to be == 10 | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,30 @@ | ||
|
||
require 'samovar' | ||
require 'stringio' | ||
|
||
module Samovar::NestedSpec | ||
class InnerA < Samovar::Command | ||
end | ||
|
||
class InnerB < Samovar::Command | ||
end | ||
|
||
class Outer < Samovar::Command | ||
nested '<command>', | ||
'inner-a' => InnerA, | ||
'inner-b' => InnerB, | ||
default: 'inner-b' | ||
end | ||
|
||
RSpec.describe Samovar::Nested do | ||
it "should select default nested command" do | ||
outer = Outer[] | ||
expect(outer.command).to be_kind_of(InnerB) | ||
end | ||
|
||
it "should select explicitly named nested command" do | ||
outer = Outer['inner-a'] | ||
expect(outer.command).to be_kind_of(InnerA) | ||
end | ||
end | ||
end |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
|
||
RSpec.describe Samovar::Options do | ||
subject(:options) do | ||
described_class.parse do | ||
option '-x <value>', "The x factor", default: 2 | ||
option '-y <value>', "The y factor" | ||
end | ||
end | ||
|
||
it "should set defaults" do | ||
values = options.parse([], nil) | ||
expect(values).to be == {x: 2} | ||
end | ||
|
||
it "should preserve current values" do | ||
values = options.parse([], {x: 1, y: 2, z: 3}) | ||
expect(values).to be == {x: 1, y: 2, z: 3} | ||
end | ||
|
||
it "should update specified values" do | ||
values = options.parse(['-x', 10], {x: 1, y: 2, z: 3}) | ||
expect(values).to be == {x: 10, y: 2, z: 3} | ||
end | ||
end |
This file was deleted.
Oops, something went wrong.