From 0d59f1ca49c9f7f3b2edaadcf590360ec66a6257 Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 24 Oct 2017 12:45:11 +0200 Subject: nix: Respect -I, --arg, --argstr Also, random cleanup to argument handling. --- src/nix-prefetch-url/nix-prefetch-url.cc | 21 +++++++++++---------- 1 file changed, 11 insertions(+), 10 deletions(-) (limited to 'src/nix-prefetch-url/nix-prefetch-url.cc') diff --git a/src/nix-prefetch-url/nix-prefetch-url.cc b/src/nix-prefetch-url/nix-prefetch-url.cc index 7e62a033b458..fef3eaa45538 100644 --- a/src/nix-prefetch-url/nix-prefetch-url.cc +++ b/src/nix-prefetch-url/nix-prefetch-url.cc @@ -4,7 +4,7 @@ #include "store-api.hh" #include "eval.hh" #include "eval-inline.hh" -#include "common-opts.hh" +#include "common-eval-args.hh" #include "attr-path.hh" #include @@ -48,15 +48,18 @@ int main(int argc, char * * argv) HashType ht = htSHA256; std::vector args; - Strings searchPath; bool printPath = getEnv("PRINT_PATH") != ""; bool fromExpr = false; string attrPath; - std::map autoArgs_; bool unpack = false; string name; - parseCmdLine(argc, argv, [&](Strings::iterator & arg, const Strings::iterator & end) { + struct MyArgs : LegacyArgs, MixEvalArgs + { + using LegacyArgs::LegacyArgs; + }; + + MyArgs myArgs(baseNameOf(argv[0]), [&](Strings::iterator & arg, const Strings::iterator & end) { if (*arg == "--help") showManPage("nix-prefetch-url"); else if (*arg == "--version") @@ -77,10 +80,6 @@ int main(int argc, char * * argv) unpack = true; else if (*arg == "--name") name = getArg(*arg, arg, end); - else if (parseAutoArgs(arg, end, autoArgs_)) - ; - else if (parseSearchPathArg(arg, end, searchPath)) - ; else if (*arg != "" && arg->at(0) == '-') return false; else @@ -88,13 +87,15 @@ int main(int argc, char * * argv) return true; }); + myArgs.parseCmdline(argvToStrings(argc, argv)); + if (args.size() > 2) throw UsageError("too many arguments"); auto store = openStore(); - EvalState state(searchPath, store); + EvalState state(myArgs.searchPath, store); - Bindings & autoArgs(*evalAutoArgs(state, autoArgs_)); + Bindings & autoArgs = *myArgs.getAutoArgs(state); /* If -A is given, get the URI from the specified Nix expression. */ -- cgit 1.4.1