mirror of
https://github.com/privatevoid-net/nix-super.git
synced 2024-11-22 05:56:15 +02:00
Merge pull request #10701 from cole-h/nix-command-warn-unknown-settings
Warn on unknown settings when the first positional is an argument
This commit is contained in:
commit
e4be8abe42
4 changed files with 42 additions and 8 deletions
28
doc/manual/rl-next/fix-silent-unknown-options
Normal file
28
doc/manual/rl-next/fix-silent-unknown-options
Normal file
|
@ -0,0 +1,28 @@
|
||||||
|
---
|
||||||
|
synopsis: Warn on unknown settings anywhere in the command line
|
||||||
|
prs: 10701
|
||||||
|
---
|
||||||
|
|
||||||
|
All `nix` commands will now properly warn when an unknown option is specified anywhere in the command line.
|
||||||
|
|
||||||
|
Before:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ nix-instantiate --option foobar baz --expr '{}'
|
||||||
|
warning: unknown setting 'foobar'
|
||||||
|
$ nix-instantiate '{}' --option foobar baz --expr
|
||||||
|
$ nix eval --expr '{}' --option foobar baz
|
||||||
|
{ }
|
||||||
|
```
|
||||||
|
|
||||||
|
After:
|
||||||
|
|
||||||
|
```console
|
||||||
|
$ nix-instantiate --option foobar baz --expr '{}'
|
||||||
|
warning: unknown setting 'foobar'
|
||||||
|
$ nix-instantiate '{}' --option foobar baz --expr
|
||||||
|
warning: unknown setting 'foobar'
|
||||||
|
$ nix eval --expr '{}' --option foobar baz
|
||||||
|
warning: unknown setting 'foobar'
|
||||||
|
{ }
|
||||||
|
```
|
|
@ -268,8 +268,6 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
verbosity = lvlError;
|
verbosity = lvlError;
|
||||||
}
|
}
|
||||||
|
|
||||||
bool argsSeen = false;
|
|
||||||
|
|
||||||
// Heuristic to see if we're invoked as a shebang script, namely,
|
// Heuristic to see if we're invoked as a shebang script, namely,
|
||||||
// if we have at least one argument, it's the name of an
|
// if we have at least one argument, it's the name of an
|
||||||
// executable file, and it starts with "#!".
|
// executable file, and it starts with "#!".
|
||||||
|
@ -336,10 +334,6 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
throw UsageError("unrecognised flag '%1%'", arg);
|
throw UsageError("unrecognised flag '%1%'", arg);
|
||||||
}
|
}
|
||||||
else {
|
else {
|
||||||
if (!argsSeen) {
|
|
||||||
argsSeen = true;
|
|
||||||
initialFlagsProcessed();
|
|
||||||
}
|
|
||||||
pos = rewriteArgs(cmdline, pos);
|
pos = rewriteArgs(cmdline, pos);
|
||||||
pendingArgs.push_back(*pos++);
|
pendingArgs.push_back(*pos++);
|
||||||
if (processArgs(pendingArgs, false))
|
if (processArgs(pendingArgs, false))
|
||||||
|
@ -349,8 +343,7 @@ void RootArgs::parseCmdline(const Strings & _cmdline, bool allowShebang)
|
||||||
|
|
||||||
processArgs(pendingArgs, true);
|
processArgs(pendingArgs, true);
|
||||||
|
|
||||||
if (!argsSeen)
|
initialFlagsProcessed();
|
||||||
initialFlagsProcessed();
|
|
||||||
|
|
||||||
/* Now that we are done parsing, make sure that any experimental
|
/* Now that we are done parsing, make sure that any experimental
|
||||||
* feature required by the flags is enabled */
|
* feature required by the flags is enabled */
|
||||||
|
|
|
@ -52,3 +52,7 @@ fi
|
||||||
|
|
||||||
# Test --arg-from-stdin.
|
# Test --arg-from-stdin.
|
||||||
[[ "$(echo bla | nix eval --raw --arg-from-stdin foo --expr '{ foo }: { inherit foo; }' foo)" = bla ]]
|
[[ "$(echo bla | nix eval --raw --arg-from-stdin foo --expr '{ foo }: { inherit foo; }' foo)" = bla ]]
|
||||||
|
|
||||||
|
# Test that unknown settings are warned about
|
||||||
|
out="$(expectStderr 0 nix eval --option foobar baz --expr '""' --raw)"
|
||||||
|
[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]]
|
||||||
|
|
|
@ -30,3 +30,12 @@ expectStderr 1 nix-instantiate --eval -E '[]' -A 'x' | grepQuiet "should be a se
|
||||||
expectStderr 1 nix-instantiate --eval -E '{}' -A '1' | grepQuiet "should be a list"
|
expectStderr 1 nix-instantiate --eval -E '{}' -A '1' | grepQuiet "should be a list"
|
||||||
expectStderr 1 nix-instantiate --eval -E '{}' -A '.' | grepQuiet "empty attribute name"
|
expectStderr 1 nix-instantiate --eval -E '{}' -A '.' | grepQuiet "empty attribute name"
|
||||||
expectStderr 1 nix-instantiate --eval -E '[]' -A '1' | grepQuiet "out of range"
|
expectStderr 1 nix-instantiate --eval -E '[]' -A '1' | grepQuiet "out of range"
|
||||||
|
|
||||||
|
# Unknown setting warning
|
||||||
|
# NOTE(cole-h): behavior is different depending on the order, which is why we test an unknown option
|
||||||
|
# before and after the `'{}'`!
|
||||||
|
out="$(expectStderr 0 nix-instantiate --option foobar baz --expr '{}')"
|
||||||
|
[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]]
|
||||||
|
|
||||||
|
out="$(expectStderr 0 nix-instantiate '{}' --option foobar baz --expr )"
|
||||||
|
[[ "$(echo "$out" | grep foobar | wc -l)" = 1 ]]
|
||||||
|
|
Loading…
Reference in a new issue