Make StorePathsCommand a subclass of InstallablesCommand
This allows commands like 'nix path-info', 'nix copy', 'nix verify' etc. to work on arbitrary installables. E.g. to copy geeqie to a binary cache: $ nix copy -r --to file:///tmp/binary-cache nixpkgs.geeqie Or to get the closure size of thunderbird: $ nix path-info -S nixpkgs.thunderbird
This commit is contained in:
parent
c769841bc4
commit
7ee81f3887
2 changed files with 33 additions and 24 deletions
|
@ -1,5 +1,6 @@
|
|||
#include "command.hh"
|
||||
#include "store-api.hh"
|
||||
#include "derivations.hh"
|
||||
|
||||
namespace nix {
|
||||
|
||||
|
@ -98,23 +99,32 @@ void StoreCommand::run()
|
|||
|
||||
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)
|
||||
{
|
||||
Paths storePaths;
|
||||
|
||||
if (all) {
|
||||
if (storePaths.size())
|
||||
if (installables.size())
|
||||
throw UsageError("‘--all’ does not expect arguments");
|
||||
for (auto & p : store->queryAllValidPaths())
|
||||
storePaths.push_back(p);
|
||||
}
|
||||
|
||||
else {
|
||||
for (auto & storePath : storePaths)
|
||||
storePath = store->followLinksToStorePath(storePath);
|
||||
for (auto & i : installables) {
|
||||
for (auto & path : i->toBuildable()) {
|
||||
if (isDerivation(path)) {
|
||||
Derivation drv = store->derivationFromPath(path);
|
||||
for (auto & output : drv.outputs)
|
||||
storePaths.push_back(output.second.path);
|
||||
} else
|
||||
storePaths.push_back(path);
|
||||
}
|
||||
}
|
||||
|
||||
if (recursive) {
|
||||
PathSet closure;
|
||||
|
|
|
@ -44,26 +44,6 @@ private:
|
|||
std::shared_ptr<Store> _store;
|
||||
};
|
||||
|
||||
/* A command that operates on zero or more store paths. */
|
||||
struct StorePathsCommand : public StoreCommand
|
||||
{
|
||||
private:
|
||||
|
||||
Paths storePaths;
|
||||
bool recursive = false;
|
||||
bool all = false;
|
||||
|
||||
public:
|
||||
|
||||
StorePathsCommand();
|
||||
|
||||
using StoreCommand::run;
|
||||
|
||||
virtual void run(ref<Store> store, Paths storePaths) = 0;
|
||||
|
||||
void run(ref<Store> store) override;
|
||||
};
|
||||
|
||||
struct Installable
|
||||
{
|
||||
virtual std::string what() = 0;
|
||||
|
@ -115,6 +95,25 @@ private:
|
|||
Value * vSourceExpr = 0;
|
||||
};
|
||||
|
||||
/* A command that operates on zero or more store paths. */
|
||||
struct StorePathsCommand : public InstallablesCommand
|
||||
{
|
||||
private:
|
||||
|
||||
bool recursive = false;
|
||||
bool all = false;
|
||||
|
||||
public:
|
||||
|
||||
StorePathsCommand();
|
||||
|
||||
using StoreCommand::run;
|
||||
|
||||
virtual void run(ref<Store> store, Paths storePaths) = 0;
|
||||
|
||||
void run(ref<Store> store) override;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, ref<Command>> Commands;
|
||||
|
||||
/* An argument parser that supports multiple subcommands,
|
||||
|
|
Loading…
Reference in a new issue