scsl  0.2.3
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. More...
 
bool Register (Subcommand scmd)
 Register adds the subcommand. It will be copied into the Commander. More...
 
Subcommand::Status Run (std::string command, int argc, char **argv)
 Try to run a subcommand registered with this Commander. More...
 

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

Constructor & Destructor Documentation

◆ Commander()

scsl::Commander::Commander ( )

A Commander is initialized empty.

Member Function Documentation

◆ Register()

bool scsl::Commander::Register ( Subcommand  scmd)

Register adds the subcommand. It will be copied into the Commander.

◆ Run()

Subcommand::Status scsl::Commander::Run ( std::string  command,
int  argc,
char **  argv 
)

Try to run a subcommand registered with this Commander.


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