1
0
Fork 0
mirror of https://github.com/NixOS/nix synced 2025-07-04 03:01:47 +02:00

Make subcommand construction in MultiCommand lazy

This commit is contained in:
Eelco Dolstra 2019-06-18 16:01:35 +02:00
parent eb18aedccb
commit a0de58f471
No known key found for this signature in database
GPG key ID: 8170B4726D7198DE
29 changed files with 73 additions and 282 deletions

View file

@ -192,7 +192,12 @@ public:
run() method. */
struct Command : virtual Args
{
virtual std::string name() = 0;
private:
std::string _name;
public:
std::string name() { return _name; }
virtual void prepare() { };
virtual void run() = 0;
@ -209,7 +214,7 @@ struct Command : virtual Args
void printHelp(const string & programName, std::ostream & out) override;
};
typedef std::map<std::string, ref<Command>> Commands;
typedef std::map<std::string, std::function<ref<Command>()>> Commands;
/* An argument parser that supports multiple subcommands,
i.e. <command> <subcommand>. */
@ -220,7 +225,7 @@ public:
std::shared_ptr<Command> command;
MultiCommand(const std::vector<ref<Command>> & commands);
MultiCommand(const Commands & commands);
void printHelp(const string & programName, std::ostream & out) override;