about summary refs log tree commit diff
path: root/src/nix/edit.cc
diff options
context:
space:
mode:
authorEelco Dolstra <edolstra@gmail.com>2017-08-29T14·18+0200
committerEelco Dolstra <edolstra@gmail.com>2017-08-29T14·18+0200
commite9c07a3b26a1e3056538a8fce49c9f7d9f1d8aba (patch)
treeb6e5559aeaa066cbb454876d1cdbffcd7582ad45 /src/nix/edit.cc
parent9b82ecbae04e36cb8f009510716268fa72a067b8 (diff)
nix edit / log: Operate on a single Installable
Diffstat (limited to 'src/nix/edit.cc')
-rw-r--r--src/nix/edit.cc54
1 files changed, 26 insertions, 28 deletions
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);
     }
 };