summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorLee Jarvis <leejarvis@fastmail.com>2016-03-19 10:20:35 +0000
committerLee Jarvis <leejarvis@fastmail.com>2016-03-19 10:20:35 +0000
commitabb43d5c68c3d3a1c00806bf90c30c74a9385753 (patch)
treef45173d08af11926d2dfb117c734a61ee36fcf88
parent601f498d572a37cb818bcb78f32aee286e8ff70a (diff)
parentd67a1b63f5232adb33acbfb03a79e51695a7ab88 (diff)
downloadslop-abb43d5c68c3d3a1c00806bf90c30c74a9385753.tar.gz
Merge pull request #191 from prees1/master
Can specify a custom banner string in Options via config
-rw-r--r--lib/slop/options.rb2
-rw-r--r--test/options_test.rb13
2 files changed, 13 insertions, 2 deletions
diff --git a/lib/slop/options.rb b/lib/slop/options.rb
index ed99c64..c1873d0 100644
--- a/lib/slop/options.rb
+++ b/lib/slop/options.rb
@@ -26,7 +26,7 @@ module Slop
def initialize(**config)
@options = []
@separators = []
- @banner = "usage: #{$0} [options]"
+ @banner = config[:banner].is_a?(String) ? config[:banner] : config.fetch(:banner, "usage: #{$0} [options]")
@config = DEFAULT_CONFIG.merge(config)
@parser = Parser.new(self, @config)
diff --git a/test/options_test.rb b/test/options_test.rb
index 65461db..bb19210 100644
--- a/test/options_test.rb
+++ b/test/options_test.rb
@@ -55,7 +55,7 @@ describe Slop::Options do
end
describe "#to_s" do
- it "is prefixed with the banner" do
+ it "is prefixed with the default banner" do
assert_match(/^usage/, @options.to_s)
end
@@ -82,4 +82,15 @@ describe Slop::Options do
assert_match(/^ -h, --help/, @options.to_s.lines.last)
end
end
+
+ describe "custom banner" do
+ it "is prefixed with defined banner" do
+ @options_config = Slop::Options.new({banner: "custom banner"})
+ assert_match(/^custom banner/, @options_config.to_s)
+ end
+ it "banner is disabled" do
+ @options_config = Slop::Options.new({banner: false})
+ assert_match("", @options_config.to_s)
+ end
+ end
end