RADLib
RADical C++ application framework

RADCLI provides command-line parsing and application utility helpers for RADLib tools and examples.

RADCLI::CommandLineParser is the core type. It is constructed with an application name, takes an optional description via setDescription(), and accepts option definitions through addOption(). Each RADCLI::Option declares a long name, an optional shortName, description, and the requiresValue, required, and defaultValue fields that control validation and defaults. parse() accepts either argc/argv or a std::vector<std::string> (where args[0] is the program name), and helpText() builds formatted usage text from the registered options.

Parsing yields a RADCLI::ParseResult. Call ok() and error() to check for failures, has() to test whether an option was explicitly provided, value() to read an option value or its default, and positionals() to read the remaining positional arguments.

RADCLI also exposes free-function application helpers: environmentVariable() and setEnvironmentVariable() for the process environment, executablePath() for the current binary path, currentUserName() for the active user, and radlibVersionString() for the RADLib version string.

Core features:

  • Long and short options.
  • Required options, defaults, flags, and positional arguments.
  • Help text generation.
  • Environment, executable path, current user, and RADLib version helpers.

Example:

RADCLI::CommandLineParser parser("radtool");
parser.setDescription("Example RADLib command-line tool.");
parser.addOption({"config", 'c', "Config file path", true, true, ""});
parser.addOption({"verbose", 'v', "Enable verbose output", false, false, ""});
RADCLI::ParseResult result = parser.parse(argc, argv);
if (!result.ok()) {
RADLOG_ERROR("cli") << result.error();
std::puts(parser.helpText().c_str());
return 1;
}
std::string configPath = result.value("config", "default.json");
bool verbose = result.has("verbose");
RADLOG_INFO("cli") << "radlib " << RADCLI::radlibVersionString()
<< " config=" << configPath;
#define RADLOG_INFO(category)
Logs with RADLogging at info level.
Definition: RADLogging.h:112
#define RADLOG_ERROR(category)
Logs with RADLogging at error level.
Definition: RADLogging.h:116
Small command-line parser for RADLib tools and examples.
Definition: RADCLI.h:60
Parsed command-line result.
Definition: RADCLI.h:37
bool has(const std::string &name) const
Returns true when option was explicitly provided.
bool ok() const
Returns true when parsing succeeded.
std::string value(const std::string &name, const std::string &defaultValue={}) const
Returns option value or defaultValue.
const std::string & error() const
Returns parser error text.
std::string radlibVersionString()
Returns the RADLib version string.