about summary refs log tree commit diff
path: root/src/nix/command.cc
diff options
context:
space:
mode:
Diffstat (limited to 'src/nix/command.cc')
-rw-r--r--src/nix/command.cc37
1 files changed, 31 insertions, 6 deletions
diff --git a/src/nix/command.cc b/src/nix/command.cc
index a89246a937c1..c8d91737d8be 100644
--- a/src/nix/command.cc
+++ b/src/nix/command.cc
@@ -5,6 +5,21 @@ namespace nix {
 
 Commands * RegisterCommand::commands = 0;
 
+void Command::printHelp(const string & programName, std::ostream & out)
+{
+    Args::printHelp(programName, out);
+
+    auto exs = examples();
+    if (!exs.empty()) {
+        out << "\n";
+        out << "Examples:\n";
+        for (auto & ex : exs)
+            out << "\n"
+                << "  " << ex.description << "\n" // FIXME: wrap
+                << "  $ " << ex.command << "\n";
+    }
+}
+
 MultiCommand::MultiCommand(const Commands & _commands)
     : commands(_commands)
 {
@@ -73,18 +88,28 @@ StorePathsCommand::StorePathsCommand()
 {
     expectArgs("paths", &storePaths);
     mkFlag('r', "recursive", "apply operation to closure of the specified paths", &recursive);
+    mkFlag(0, "all", "apply operation to the entire store", &all);
 }
 
 void StorePathsCommand::run(ref<Store> store)
 {
-    for (auto & storePath : storePaths)
-        storePath = followLinksToStorePath(storePath);
+    if (all) {
+        if (storePaths.size())
+            throw UsageError("‘--all’ does not expect arguments");
+        for (auto & p : store->queryAllValidPaths())
+            storePaths.push_back(p);
+    }
 
-    if (recursive) {
-        PathSet closure;
+    else {
         for (auto & storePath : storePaths)
-            store->computeFSClosure(storePath, closure, false, false);
-        storePaths = store->topoSortPaths(closure);
+            storePath = followLinksToStorePath(storePath);
+
+        if (recursive) {
+            PathSet closure;
+            for (auto & storePath : storePaths)
+                store->computeFSClosure(storePath, closure, false, false);
+            storePaths = store->topoSortPaths(closure);
+        }
     }
 
     run(store, storePaths);