-
Notifications
You must be signed in to change notification settings - Fork 8
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Allow specifying descriptive argument for flag in short and/or long.
- Loading branch information
Showing
4 changed files
with
129 additions
and
11 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
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
require "./spec_helper" | ||
|
||
describe Commander::Flag do | ||
|
||
it "parses descriptive argument from short" do | ||
flag = Commander::Flag.new do |flag| | ||
flag.name = "suffix" | ||
flag.description = flag.name | ||
flag.short = "-s DIR" | ||
flag.long = "--suffix" | ||
flag.default = "" | ||
end | ||
|
||
flag.long.should eq("--suffix") | ||
flag.short.should eq("-s") | ||
flag.arg.should eq("DIR") | ||
end | ||
|
||
it "parses descriptive argument from long" do | ||
flag = Commander::Flag.new do |flag| | ||
flag.name = "suffix" | ||
flag.description = flag.name | ||
flag.short = "-s" | ||
flag.long = "--suffix DIR" | ||
flag.default = "" | ||
end | ||
|
||
flag.long.should eq("--suffix") | ||
flag.short.should eq("-s") | ||
flag.arg.should eq("DIR") | ||
end | ||
|
||
it "parses descriptive argument from short if both present" do | ||
flag = Commander::Flag.new do |flag| | ||
flag.name = "suffix" | ||
flag.description = flag.name | ||
flag.short = "-s DIR" | ||
flag.long = "--suffix DIR" | ||
flag.default = "" | ||
end | ||
|
||
flag.long.should eq("--suffix") | ||
flag.short.should eq("-s") | ||
flag.arg.should eq("DIR") | ||
end | ||
|
||
it "ignores descriptive argument if absent from both short and long" do | ||
flag = Commander::Flag.new do |flag| | ||
flag.name = "suffix" | ||
flag.description = flag.name | ||
flag.short = "-s" | ||
flag.long = "--suffix" | ||
flag.default = "" | ||
end | ||
|
||
flag.long.should eq("--suffix") | ||
flag.short.should eq("-s") | ||
flag.arg.should be_nil | ||
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
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