vg
tools for working with variation graphs
|
#include <subcommand.hpp>
Public Member Functions | |
Subcommand (std::string name, std::string description, CommandCategory category, int priority, std::function< int(int, char **)> main_function) | |
Subcommand (std::string name, std::string description, CommandCategory category, std::function< int(int, char **)> main_function) | |
Subcommand (std::string name, std::string description, std::function< int(int, char **)> main_function) | |
const std::string & | get_name () const |
const std::string & | get_description () const |
const CommandCategory & | get_category () const |
const int & | get_priority () const |
const int | operator() (int argc, char **argv) const |
Static Public Member Functions | |
static const Subcommand * | get (int argc, char **argv) |
static void | for_each (const std::function< void(const Subcommand &)> &lambda) |
static void | for_each (CommandCategory category, const std::function< void(const Subcommand &)> &lambda) |
Private Member Functions | |
const std::function< int(int, char **)> & | get_main () const |
Static Private Member Functions | |
static std::map< std::string, Subcommand * > & | get_registry () |
Private Attributes | |
std::string | name |
std::string | description |
CommandCategory | category |
int | priority |
std::function< int(int, char **)> | main_function |
Represents a subcommand with a name, a description, and some functions. Registers itself on construction in a static registry, and provides static functions for enumerating through that registry.
vg::subcommand::Subcommand::Subcommand | ( | std::string | name, |
std::string | description, | ||
CommandCategory | category, | ||
int | priority, | ||
std::function< int(int, char **)> | main_function | ||
) |
Make and register a subcommand with the given name and description, in the given category, with the given priority (lower is better), which calls the given main function when invoked.
vg::subcommand::Subcommand::Subcommand | ( | std::string | name, |
std::string | description, | ||
CommandCategory | category, | ||
std::function< int(int, char **)> | main_function | ||
) |
Make and register a subcommand with the given name and description, in the given category, with worst priority, which calls the given main function when invoked.
vg::subcommand::Subcommand::Subcommand | ( | std::string | name, |
std::string | description, | ||
std::function< int(int, char **)> | main_function | ||
) |
Make and register a subcommand with the given name and description, in the WIDGET category, with worst priority, which calls the given main function when invoked.
|
static |
Call the given lambda with each known subcommand in the given category, in order.
|
static |
Call the given lambda with each known subcommand, in order.
|
static |
Get the appropriate subcommand to handle the given arguments, or nullptr if no matching subcommand is found.
const CommandCategory & vg::subcommand::Subcommand::get_category | ( | ) | const |
Get the category of a subcommand, which determines who might want to use it and why.
const std::string & vg::subcommand::Subcommand::get_description | ( | ) | const |
Get the description of a subcommand.
|
private |
Get the main function of a subcommand.
const std::string & vg::subcommand::Subcommand::get_name | ( | ) | const |
Get the name of a subcommand.
const int & vg::subcommand::Subcommand::get_priority | ( | ) | const |
Get the priority level of a subcommand (lower is more important).
|
staticprivate |
Since we can't rely on a static member field being constructed before any static code that creates actual subcommands gets run, we rely on keeping the registry in a static variable inside a static method, so it gets constructed on first use. Note that at shutdown some of the poinbters in the registry may be to already-destructed static objects.
const int vg::subcommand::Subcommand::operator() | ( | int | argc, |
char ** | argv | ||
) | const |
Run the main function of a subcommand. Return the return code.
|
private |
|
private |
|
private |
|
private |
|
private |