Move code around

This commit is contained in:
Eelco Dolstra 2017-04-25 12:06:32 +02:00
parent 6267d74889
commit c769841bc4
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
8 changed files with 68 additions and 80 deletions

View file

@ -4,6 +4,9 @@
namespace nix {
struct Value;
class EvalState;
/* A command is an argument parser that can be executed by calling its
run() method. */
struct Command : virtual Args
@ -61,6 +64,57 @@ public:
void run(ref<Store> store) override;
};
struct Installable
{
virtual std::string what() = 0;
virtual PathSet toBuildable()
{
throw Error("argument %s cannot be built", what());
}
virtual Value * toValue(EvalState & state)
{
throw Error("argument %s cannot be evaluated", what());
}
};
/* A command that operates on a list of "installables", which can be
store paths, attribute paths, Nix expressions, etc. */
struct InstallablesCommand : virtual Args, StoreCommand
{
std::vector<std::shared_ptr<Installable>> installables;
Path file;
InstallablesCommand()
{
mkFlag('f', "file", "file", "evaluate FILE rather than the default", &file);
expectArgs("installables", &_installables);
}
/* Return a value representing the Nix expression from which we
are installing. This is either the file specified by --file,
or an attribute set constructed from $NIX_PATH, e.g. { nixpkgs
= import ...; bla = import ...; }. */
Value * getSourceExpr(EvalState & state);
std::vector<std::shared_ptr<Installable>> parseInstallables(ref<Store> store, Strings installables);
PathSet buildInstallables(ref<Store> store, bool dryRun);
ref<EvalState> getEvalState();
void prepare() override;
private:
Strings _installables;
std::shared_ptr<EvalState> evalState;
Value * vSourceExpr = 0;
};
typedef std::map<std::string, ref<Command>> Commands;
/* An argument parser that supports multiple subcommands,