From e9c07a3b26a1e3056538a8fce49c9f7d9f1d8aba Mon Sep 17 00:00:00 2001 From: Eelco Dolstra Date: Tue, 29 Aug 2017 16:18:00 +0200 Subject: nix edit / log: Operate on a single Installable --- src/nix/edit.cc | 54 ++++++++++++++++++++++++++---------------------------- 1 file changed, 26 insertions(+), 28 deletions(-) (limited to 'src/nix/edit.cc') diff --git a/src/nix/edit.cc b/src/nix/edit.cc index fd07913bcfa2..127be321eee2 100644 --- a/src/nix/edit.cc +++ b/src/nix/edit.cc @@ -8,7 +8,7 @@ using namespace nix; -struct CmdEdit : InstallablesCommand +struct CmdEdit : InstallableCommand { std::string name() override { @@ -34,44 +34,42 @@ struct CmdEdit : InstallablesCommand { auto state = getEvalState(); - for (auto & i : installables) { - auto v = i->toValue(*state); + auto v = installable->toValue(*state); - Value * v2; - try { - auto dummyArgs = state->allocBindings(0); - v2 = findAlongAttrPath(*state, "meta.position", *dummyArgs, *v); - } catch (Error &) { - throw Error("package '%s' has no source location information", i->what()); - } + Value * v2; + try { + auto dummyArgs = state->allocBindings(0); + v2 = findAlongAttrPath(*state, "meta.position", *dummyArgs, *v); + } catch (Error &) { + throw Error("package '%s' has no source location information", installable->what()); + } - auto pos = state->forceString(*v2); - debug("position is %s", pos); + auto pos = state->forceString(*v2); + debug("position is %s", pos); - auto colon = pos.rfind(':'); - if (colon == std::string::npos) - throw Error("cannot parse meta.position attribute '%s'", pos); + auto colon = pos.rfind(':'); + if (colon == std::string::npos) + throw Error("cannot parse meta.position attribute '%s'", pos); - std::string filename(pos, 0, colon); - int lineno = std::stoi(std::string(pos, colon + 1)); + std::string filename(pos, 0, colon); + int lineno = std::stoi(std::string(pos, colon + 1)); - auto editor = getEnv("EDITOR", "cat"); + auto editor = getEnv("EDITOR", "cat"); - Strings args{editor}; + Strings args{editor}; - if (editor.find("emacs") != std::string::npos || - editor.find("nano") != std::string::npos || - editor.find("vim") != std::string::npos) - args.push_back(fmt("+%d", lineno)); + if (editor.find("emacs") != std::string::npos || + editor.find("nano") != std::string::npos || + editor.find("vim") != std::string::npos) + args.push_back(fmt("+%d", lineno)); - args.push_back(filename); + args.push_back(filename); - stopProgressBar(); + stopProgressBar(); - execvp(editor.c_str(), stringsToCharPtrs(args).data()); + execvp(editor.c_str(), stringsToCharPtrs(args).data()); - throw SysError("cannot run editor '%s'", editor); - } + throw SysError("cannot run editor '%s'", editor); } }; -- cgit 1.4.1