scsl 1.0.1
Shimmering Clarity Standard Library
Loading...
Searching...
No Matches
Public Member Functions | List of all members
scsl::Commander Class Reference

Subcommander manager for programs. More...

#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, std::vector< std::string > args)
 Try to run a subcommand registered with this Commander.
 

Detailed Description

Subcommander manager for programs.

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);
Subcommander manager for programs.
Definition Commander.h:112
Subcommand::Status Run(std::string command, std::vector< std::string > args)
Try to run a subcommand registered with this Commander.
bool Register(Subcommand scmd)
Register adds the subcommand. It will be copied into the Commander.
Subcommands used by Commander.
Definition Commander.h:54

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,
std::vector< std::string >  args 
)

Try to run a subcommand registered with this Commander.


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