1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-06-27 04:21:16 +02:00

nix run: Allow passing a command to execute

E.g.

  nix run nixpkgs.hello -c hello --greeting Hallo

Note that unlike "nix-shell --command", no quoting of arguments is
necessary.

"-c" (short for "--command") cannot be combined with "--" because they
both consume all remaining arguments. But since installables shouldn't
start with a dash, this is unlikely to cause problems.
This commit is contained in:
Eelco Dolstra 2017-08-29 14:28:57 +02:00
parent 93a5ef0516
commit 5cc8609e30
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
3 changed files with 19 additions and 3 deletions

View file

@ -102,9 +102,11 @@ bool Args::processFlag(Strings::iterator & pos, Strings::iterator end)
++pos;
Strings args;
for (size_t n = 0 ; n < flag.arity; ++n) {
if (pos == end)
if (pos == end) {
if (flag.arity == ArityAny) break;
throw UsageError(format("flag '%1%' requires %2% argument(s)")
% name % flag.arity);
}
args.push_back(*pos++);
}
flag.handler(args);

View file

@ -26,6 +26,8 @@ public:
protected:
static const size_t ArityAny = std::numeric_limits<size_t>::max();
/* Flags. */
struct Flag
{