[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
126/376: Handle compound single dash options properly
From: |
Ludovic Courtès |
Subject: |
126/376: Handle compound single dash options properly |
Date: |
Wed, 28 Jan 2015 22:04:29 +0000 |
civodul pushed a commit to tag 1.8
in repository guix.
commit 5f05197df460bafd9a4f451d69757401b35a1180
Author: Eelco Dolstra <address@hidden>
Date: Wed Aug 13 04:03:05 2014 +0200
Handle compound single dash options properly
So now
nix-instantiate --eval -E '{x}: x' --argstr x -xyzzy
correctly prints "-xyzzy", rather than giving an error.
Issue NixOS/hydra#176.
---
src/libmain/shared.cc | 29 ++++++++++++++---------------
1 files changed, 14 insertions(+), 15 deletions(-)
diff --git a/src/libmain/shared.cc b/src/libmain/shared.cc
index ec05db0..9ac9d27 100644
--- a/src/libmain/shared.cc
+++ b/src/libmain/shared.cc
@@ -159,29 +159,28 @@ void parseCmdLine(int argc, char * * argv,
std::function<bool(Strings::iterator & arg, const Strings::iterator &
end)> parseArg)
{
/* Put the arguments in a vector. */
- Strings args, remaining;
+ Strings args;
+ argc--; argv++;
while (argc--) args.push_back(*argv++);
- args.erase(args.begin());
- /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'), and
- ignore options for the ATerm library. */
+ /* Process default options. */
for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
string arg = *i;
- if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' &&
!isdigit(arg[1])) {
- for (unsigned int j = 1; j < arg.length(); j++)
+
+ /* Expand compound dash options (i.e., `-qlf' -> `-q -l -f'). */
+ if (arg.length() > 2 && arg[0] == '-' && arg[1] != '-' &&
isalpha(arg[1])) {
+ *i = (string) "-" + arg[1];
+ auto next = i; ++next;
+ for (unsigned int j = 2; j < arg.length(); j++)
if (isalpha(arg[j]))
- remaining.push_back((string) "-" + arg[j]);
- else {
- remaining.push_back(string(arg, j));
+ args.insert(next, (string) "-" + arg[j]);
+ else {
+ args.insert(next, string(arg, j));
break;
}
- } else remaining.push_back(arg);
- }
- args = remaining;
+ arg = *i;
+ }
- /* Process default options. */
- for (Strings::iterator i = args.begin(); i != args.end(); ++i) {
- string arg = *i;
if (arg == "--verbose" || arg == "-v") verbosity = (Verbosity)
(verbosity + 1);
else if (arg == "--quiet") verbosity = verbosity > lvlError ?
(Verbosity) (verbosity - 1) : lvlError;
else if (arg == "--log-type") {
- 118/376: install-nix-from-closure.sh: Use https channel if possible, (continued)
- 118/376: install-nix-from-closure.sh: Use https channel if possible, Ludovic Courtès, 2015/01/28
- 114/376: Refactor, Ludovic Courtès, 2015/01/28
- 117/376: Remove unnecessary call to addTempRoot(), Ludovic Courtès, 2015/01/28
- 115/376: Move some options out of globals, Ludovic Courtès, 2015/01/28
- 116/376: Doh, Ludovic Courtès, 2015/01/28
- 112/376: Add option ‘build-extra-chroot-dirs’, Ludovic Courtès, 2015/01/28
- 111/376: Get rid of "killing <pid>" message for unused build hooks, Ludovic Courtès, 2015/01/28
- 129/376: Remove log2html.xsl and friends, Ludovic Courtès, 2015/01/28
- 122/376: Warn about untrusted binary caches in extra-binary-caches, Ludovic Courtès, 2015/01/28
- 113/376: Update manual, Ludovic Courtès, 2015/01/28
- 126/376: Handle compound single dash options properly,
Ludovic Courtès <=
- 124/376: Fix warning about non-existant -I directories, Ludovic Courtès, 2015/01/28
- 127/376: Use regular file GC roots if possible, Ludovic Courtès, 2015/01/28
- 128/376: nix-log2xml: Handle UTF-8 characters, Ludovic Courtès, 2015/01/28
- 132/376: nix-shell: Use $XDG_RUNTIME_DIR, Ludovic Courtès, 2015/01/28
- 120/376: download-from-binary-cache.pl: Respect $SSL_CERT_FILE, Ludovic Courtès, 2015/01/28
- 123/376: Remove pointless NIX_LOG_TYPE environment variable, Ludovic Courtès, 2015/01/28
- 136/376: Propagate remote timeouts properly, Ludovic Courtès, 2015/01/28
- 131/376: Use $XDG_RUNTIME_DIR for temporary files, Ludovic Courtès, 2015/01/28
- 137/376: Reduce verbosity, Ludovic Courtès, 2015/01/28
- 133/376: Fix download-via-ssh, Ludovic Courtès, 2015/01/28