mirror of
https://github.com/NixOS/nix.git
synced 2025-11-13 14:02:42 +01:00
Move Command and MultiCommand to libutil
This commit is contained in:
parent
15a16e5c05
commit
f70434b1fb
5 changed files with 115 additions and 115 deletions
|
|
@ -11,27 +11,6 @@ struct Value;
|
|||
class Bindings;
|
||||
class EvalState;
|
||||
|
||||
/* A command is an argument parser that can be executed by calling its
|
||||
run() method. */
|
||||
struct Command : virtual Args
|
||||
{
|
||||
virtual std::string name() = 0;
|
||||
virtual void prepare() { };
|
||||
virtual void run() = 0;
|
||||
|
||||
struct Example
|
||||
{
|
||||
std::string description;
|
||||
std::string command;
|
||||
};
|
||||
|
||||
typedef std::list<Example> Examples;
|
||||
|
||||
virtual Examples examples() { return Examples(); }
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override;
|
||||
};
|
||||
|
||||
class Store;
|
||||
|
||||
/* A command that require a Nix store. */
|
||||
|
|
@ -162,26 +141,6 @@ struct StorePathCommand : public InstallablesCommand
|
|||
void run(ref<Store> store) override;
|
||||
};
|
||||
|
||||
typedef std::map<std::string, ref<Command>> Commands;
|
||||
|
||||
/* An argument parser that supports multiple subcommands,
|
||||
i.e. ‘<command> <subcommand>’. */
|
||||
class MultiCommand : virtual Args
|
||||
{
|
||||
public:
|
||||
Commands commands;
|
||||
|
||||
std::shared_ptr<Command> command;
|
||||
|
||||
MultiCommand(const std::vector<ref<Command>> & commands);
|
||||
|
||||
void printHelp(const string & programName, std::ostream & out) override;
|
||||
|
||||
bool processFlag(Strings::iterator & pos, Strings::iterator end) override;
|
||||
|
||||
bool processArgs(const Strings & args, bool finish) override;
|
||||
};
|
||||
|
||||
/* A helper class for registering commands globally. */
|
||||
struct RegisterCommand
|
||||
{
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue