Permalink
Browse files

Added separator as second arg of split_commandline_args

  • Loading branch information...
blambeau committed Aug 6, 2011
1 parent a894fe9 commit 29ae87d826d1e0c733343e08aa76657042fe8809
Showing with 15 additions and 3 deletions.
  1. +2 −0 CHANGELOG.md
  2. +4 −3 lib/quickl.rb
  3. +9 −0 spec/quickl/test_split_commandline_args.rb
View
@@ -9,6 +9,8 @@
* Command.documentation now takes an optional Hash of options, which is passed
as second argument to the documentation extractor (the first one being the
command class itself).
+ * Quickl.split_commandline_args now accepts the separator on which splitting
+ occurs as second argument.
* Breaking changes
View
@@ -186,13 +186,14 @@ def self.parse_commandline_args(args)
end
#
- # Splits an array `args` on '--' option separator.
+ # Splits an array `args` a separator, the option separator
+ # '--' by default.
#
- def self.split_commandline_args(args)
+ def self.split_commandline_args(args, separator = '--')
args = args.dup
result, current = [], []
until args.empty?
- if (x = args.shift) == "--"
+ if (x = args.shift) == separator
result << current
current = []
else
@@ -36,4 +36,13 @@
it { should eq(expected) }
end
+ describe "with a specific separator" do
+ subject{ Quickl.split_commandline_args(args, '|') }
+ let(:args){ %w{hello | hello2 hello3 | x } }
+ let(:expected){[
+ %w{hello}, %w{hello2 hello3}, %w{x}
+ ]}
+ it { should eq(expected) }
+ end
+
end

0 comments on commit 29ae87d

Please sign in to comment.