From 5cc8609e30ab4f76053f3159c51ea78d9215bc8c Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Aug 2017 14:28:57 +0200 Subject: 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. --- src/libutil/args.cc | 4 +++- 1 file changed, 3 insertions(+), 1 deletion(-) (limited to 'src/libutil/args.cc') diff --git a/src/libutil/args.cc b/src/libutil/args.cc index 2b72079f2b47..d17a1e7a9abb 100644 --- a/src/libutil/args.cc +++ b/src/libutil/args.cc @@ -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); -- cgit 1.4.1