21#include <unordered_map>
23#include "cli_config.h"
24#include "commands/command_tree.h"
25#include "commands/docwriting/docwriting.h"
26#include "logging/logger.h"
27#include "parsing/parser.h"
29#define RUN_CLI_APP(cliInstance, argc_, argv_) \
32 return cliInstance.run(argc_, argv_); \
34 catch (const std::exception &e) \
36 cliInstance.Logger().error() << e.what() << std::endl; \
50 explicit CliApp(std::string_view executableName);
52 explicit CliApp(
const CliConfig &config, std::unique_ptr<logging::AbstractLogger> logger);
75 int run(
int argc,
char *argv[]);
99 void setLogger(std::unique_ptr<logging::Logger> &&newLogger) { logger = std::move(newLogger); }
102 int internalRun(std::span<char *const> args);
105 bool initialized{
false};
106 commands::CommandTree commandsTree;
108 std::unique_ptr<CliConfig> configuration;
109 std::unique_ptr<logging::AbstractLogger> logger;
111 parsing::Parser parser;
Main class representing a command-line application.
Definition cli_app.h:44
commands::Command * getMainCommand()
Get the command tree used by the CLI application.
Definition cli_app.h:87
CliApp & withCommand(std::unique_ptr< commands::Command > subCommandPtr)
Add a new command to the application.
Definition cli_app.cpp:56
logging::AbstractLogger & Logger()
Get the logger instance used by the CLI application.
Definition cli_app.h:79
void setLogger(std::unique_ptr< logging::Logger > &&newLogger)
Set the logger instance used by the CLI application.
Definition cli_app.h:99
const commands::CommandTree & getCommandTree() const
Get the command tree used by the CLI application.
Definition cli_app.h:83
commands::docwriting::DocWriter & getDocWriter()
Get the documentation writer used by the CLI application.
Definition cli_app.h:95
int run(int argc, char *argv[])
Run the CLI application with the given arguments.
Definition cli_app.cpp:80
void init()
Initialize the CLI application, preparing it for execution This method sets up internal structures an...
Definition cli_app.cpp:62
CliConfig & getConfig()
Get the configuration used by the CLI application.
Definition cli_app.h:91
Tree structure to manage commands and their subcommands.
Definition command_tree.h:56
Command * getRootCommand()
Get the root command of the tree.
Definition command_tree.h:120
Represents a command in the CLI application.
Definition command.h:36
Documentation writer for CLI commands. Consists of formatters for commands and arguments.
Definition docwriting.h:34
Abstract base class for logger implementations.
Definition logger.h:31
Holds the configuration for the CLI application.
Definition cli_config.h:24