diff options
author | Eelco Dolstra <edolstra@gmail.com> | 2017-10-24T10·45+0200 |
---|---|---|
committer | Eelco Dolstra <edolstra@gmail.com> | 2017-10-24T10·58+0200 |
commit | 0d59f1ca49c9f7f3b2edaadcf590360ec66a6257 (patch) | |
tree | a03d53d84fb61eb354e2634705d8a076f0c1c76d /src/nix-env | |
parent | 25f32625e2f2a3a1e1b3a3811da82f21c3a3b880 (diff) |
nix: Respect -I, --arg, --argstr
Also, random cleanup to argument handling.
Diffstat (limited to 'src/nix-env')
-rw-r--r-- | src/nix-env/nix-env.cc | 22 |
1 files changed, 12 insertions, 10 deletions
diff --git a/src/nix-env/nix-env.cc b/src/nix-env/nix-env.cc index 94fbc09f6642..016caf6d2346 100644 --- a/src/nix-env/nix-env.cc +++ b/src/nix-env/nix-env.cc @@ -1,5 +1,5 @@ #include "attr-path.hh" -#include "common-opts.hh" +#include "common-eval-args.hh" #include "derivations.hh" #include "eval.hh" #include "get-drvs.hh" @@ -1309,8 +1309,7 @@ int main(int argc, char * * argv) initNix(); initGC(); - Strings opFlags, opArgs, searchPath; - std::map<string, string> autoArgs_; + Strings opFlags, opArgs; Operation op = 0; RepairFlag repair = NoRepair; string file; @@ -1326,7 +1325,12 @@ int main(int argc, char * * argv) globals.removeAll = false; globals.prebuiltOnly = false; - 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) { Operation oldOp = op; if (*arg == "--help") @@ -1335,10 +1339,6 @@ int main(int argc, char * * argv) op = opVersion; else if (*arg == "--install" || *arg == "-i") op = opInstall; - else if (parseAutoArgs(arg, end, autoArgs_)) - ; - else if (parseSearchPathArg(arg, end, searchPath)) - ; else if (*arg == "--force-name") // undocumented flag for nix-install-package globals.forceName = getArg(*arg, arg, end); else if (*arg == "--uninstall" || *arg == "-e") @@ -1391,17 +1391,19 @@ int main(int argc, char * * argv) return true; }); + myArgs.parseCmdline(argvToStrings(argc, argv)); + if (!op) throw UsageError("no operation specified"); auto store = openStore(); - globals.state = std::shared_ptr<EvalState>(new EvalState(searchPath, store)); + globals.state = std::shared_ptr<EvalState>(new EvalState(myArgs.searchPath, store)); globals.state->repair = repair; if (file != "") globals.instSource.nixExprPath = lookupFileArg(*globals.state, file); - globals.instSource.autoArgs = evalAutoArgs(*globals.state, autoArgs_); + globals.instSource.autoArgs = myArgs.getAutoArgs(*globals.state); if (globals.profile == "") globals.profile = getEnv("NIX_PROFILE", ""); |