scsl  0.2.0
Shimmering Clarity Standard Library
Public Member Functions | List of all members
scsl::Commander Class Reference

#include <Commander.h>

Public Member Functions

 Commander ()
 A Commander is initialized empty.
 
bool Register (Subcommand scmd)
 Register adds the subcommand. It will be copied into the Commander.
 
Subcommand::Status Run (std::string command, int argc, char **argv)
 Try to run a subcommand registered with this Commander.
 

Detailed Description

Commander collects subcommands and can run the apppropriate one.

For example:

auto command = string(argv[optind++]);
Commander commander;
commander.Register(Subcommand("list", 0, listFiles));
commander.Register(Subcommand("new", 1, newPhonebook));
commander.Register(Subcommand("del", 1, delKey));
commander.Register(Subcommand("has", 1, hasKey));
commander.Register(Subcommand("get", 1, getKey));
commander.Register(Subcommand("put", 2, putKey));
auto result = commander.Run(command, argc-optind, argv+optind);
Commander()
A Commander is initialized empty.
Definition: Commander.cc:47

The documentation for this class was generated from the following files: