- Command tree support
- Named and positional parameters
- Flags
- Static and dynamic commands
- Compile time structures
- Default values for optional parameters
ncs_root(my_commands) // my_commands : generated structure
ncsi::command help{ this, "help", [this]{ cli.help(); }, "Display this help" };
ncsi::command version{ this, "version", []{ std::cout << "0.2.1"; }, "Display program version" };
ncs_root_()
int main(int argc, const char* argv[])
{
ncs::cli cli{ argv[0] };
nc_commands nc{ cli };
cli.process(argc, argv);
return 0;
}Assuming the program name is "ncs", you can write
ncs helpncs version
The module is the root name of a command tree
ncs_root(my_commands)
ncs_command(ncs_module) // Use the name "ncs_module" to use the module
ncs_required(path, std::string, "File path")
ncs_command_(ncs_module, [this](auto&& input){ std::cout << input[ncs_module.path]; }, "")
ncs_root_()
int main(int argc, const char* argv[])
{
ncs::cli cli{ argv[0] };
nc_commands nc{ cli };
cli.process(argc, argv);
return 0;
}ncs file.ext
struct compiler
{
template<class T>
void make_project(const ncs::named_parameters<T>& input)
{
std::cout << input[input.param.name] << std::endl;
if (input.has(input.param.vcs)) std::cout << input[input.param.vcs] << std::endl;
std::cout << input[input.param.verbose] << std::endl;
std::cout << input[input.param.j] << std::endl;
}
};
struct ngl_cli : public ncs::basic_cli<::ngl_cli>
{
ngl_cli(std::string module_name, ::compiler& c) : ncs::basic_cli<::ngl_cli>(std::move(module_name)), compiler{ c } {}
::compiler& compiler;
};
ncs_root(nc_commands, ::ngl_cli)
ncsi::command help{ this, "help", [this]{ cli.help(); }, "Display this help" };
ncsi::command version{ this, "version", []{ std::cout << "0.2.1"; }, "Display compiler version" };
// description is optional
// bool parameters are interpreted as flags
// ncs_required, ncs_optional, ncs_flag are aliases for ncs_parameter
ncs_node(project)
ncs_command(add)
ncs_required(name, std::string, "Project name")
ncs_optional(vcs, std::string, "git", "Initialize VCS")
ncs_flag(verbose)
ncs_parameter(j, int, 4, "Threads to build")
ncs_command_(add, [this](auto&& input){ cli.compiler.make_project(ncs::named_parameters(add, input)); }, "Add a new project")
ncs_node_(project)
ncs_root_()
int main(int argc, const char* argv[])
{
::compiler compiler;
::ngl_cli ngl_cli{ argv[0], compiler };
nc_commands nc{ ngl_cli };
ngl_cli.process(argc, argv);
return 0;
}Assuming the program name is "ncs", you can write
ncs project add -name:my_project -vcs -j:4 -verbose
Using those parameters definition and a program named "nc"
ncs_node(project)
ncs_command(add)
ncs_required(name, std::string, "Project name")
ncs_optional(vcs, std::string, "git", "Initialize VCS")
ncs_flag(verbose)
ncs_parameter(j, int, 4, "Threads to build")
ncs_command_(add, [this](auto&& input){ cli.compiler.make_project(ncs::named_parameters(add, input)); }, "Add a new project")
ncs_node_(project)
-
todo
nc projectError: display available commands -
nc project addError: missing parameter -
nc project add -nameError: missing parameter value -
nc project add -name:my_projectOk: vcs does not exist in input but default value is accessible (use input.has(input.param.vcs) if you need to check its existence) -
nc project add -name:my_project -vcs:nvsOk, use explicit value -
Full command:
nc project add -name:my_project -vcs -verbose -j:4