[CommandLine] Allow grouping options which can have values.
This patch allows all forms of values for options to be used at the end
of a group. With the fix, it is possible to follow the way GNU binutils
tools handle grouping options better. For example, the -j option can be
used with objdump in any of the following ways:
$ objdump -d -j .text a.o
$ objdump -d -j.text a.o
$ objdump -dj .text a.o
$ objdump -dj.text a.o
Differential Revision: https://reviews.llvm.org/D58711
llvm-svn: 355185
diff --git a/llvm/docs/CommandLine.rst b/llvm/docs/CommandLine.rst
index 8f3207e..46ba6d3 100644
--- a/llvm/docs/CommandLine.rst
+++ b/llvm/docs/CommandLine.rst
@@ -1168,12 +1168,18 @@
.. _grouping:
.. _cl::Grouping:
-* The **cl::Grouping** modifier is used to implement Unix-style tools (like
- ``ls``) that have lots of single letter arguments, but only require a single
- dash. For example, the '``ls -labF``' command actually enables four different
- options, all of which are single letters. Note that **cl::Grouping** options
- can have values only if they are used separately or at the end of the groups.
- It is a runtime error if such an option is used elsewhere in the group.
+Controlling options grouping
+^^^^^^^^^^^^^^^^^^^^^^^^^^^^
+
+The **cl::Grouping** modifier can be combined with any formatting types except
+for `cl::Positional`_. It is used to implement Unix-style tools (like ``ls``)
+that have lots of single letter arguments, but only require a single dash.
+For example, the '``ls -labF``' command actually enables four different options,
+all of which are single letters.
+
+Note that **cl::Grouping** options can have values only if they are used
+separately or at the end of the groups. For `cl::ValueRequired`_, it is
+a runtime error if such an option is used elsewhere in the group.
The CommandLine library does not restrict how you use the **cl::Prefix** or
**cl::Grouping** modifiers, but it is possible to specify ambiguous argument
@@ -1188,19 +1194,24 @@
parse(string OrigInput) {
- 1. string input = OrigInput;
- 2. if (isOption(input)) return getOption(input).parse(); // Normal option
- 3. while (!isOption(input) && !input.empty()) input.pop_back(); // Remove the last letter
- 4. if (input.empty()) return error(); // No matching option
- 5. if (getOption(input).isPrefix())
- return getOption(input).parse(input);
- 6. while (!input.empty()) { // Must be grouping options
- getOption(input).parse();
- OrigInput.erase(OrigInput.begin(), OrigInput.begin()+input.length());
- input = OrigInput;
- while (!isOption(input) && !input.empty()) input.pop_back();
+ 1. string Input = OrigInput;
+ 2. if (isOption(Input)) return getOption(Input).parse(); // Normal option
+ 3. while (!Input.empty() && !isOption(Input)) Input.pop_back(); // Remove the last letter
+ 4. while (!Input.empty()) {
+ string MaybeValue = OrigInput.substr(Input.length())
+ if (getOption(Input).isPrefix())
+ return getOption(Input).parse(MaybeValue)
+ if (!MaybeValue.empty() && MaybeValue[0] == '=')
+ return getOption(Input).parse(MaybeValue.substr(1))
+ if (!getOption(Input).isGrouping())
+ return error()
+ getOption(Input).parse()
+ Input = OrigInput = MaybeValue
+ while (!Input.empty() && !isOption(Input)) Input.pop_back();
+ if (!Input.empty() && !getOption(Input).isGrouping())
+ return error()
}
- 7. if (!OrigInput.empty()) error();
+ 5. if (!OrigInput.empty()) error();
}
@@ -1240,8 +1251,6 @@
with ``cl::CommaSeparated``, this modifier only makes sense with a `cl::list`_
option.
-So far, these are the only three miscellaneous option modifiers.
-
.. _response files:
Response files