9#define COMMAND_DESCRIPTION(str) \
10 std::string_view description() const override { \
11 static constexpr char description_str[] = str; \
12 return description_str; \
15template <
typename,
typename = std::
void_t<>>
19struct has_options<T, std::void_t<decltype(T::options_)>> : std::true_type {};
21template <
typename Derived>
26 constexpr int OPTION_WIDTH = 26;
29 std::cout <<
wrapped(s, 0) <<
"\n";
32 if (command_options) {
33 std::vector<const CliOption*> vector_arguments, vector_options;
36 vector_arguments.push_back(opt);
38 vector_options.push_back(opt);
45 << (!vector_options.empty() ?
" [OPTIONS]" :
"")
46 << (!vector_arguments.empty() ?
" [--] [ARGUMENTS]" :
"")
49 if (!vector_arguments.empty()) {
52 for (
const auto& item : vector_arguments) {
53 std::string opts_str =
" ";
57 std::cout << std::left << std::setw(OPTION_WIDTH) << opts_str;
58 if (item->description !=
nullptr) {
59 std::cout <<
wrapped(item->description, OPTION_WIDTH);
65 if (!vector_options.empty()) {
66 std::sort(vector_options.begin(), vector_options.end(), [](
const CliOption* a,
const CliOption* b) {
67 return std::string_view(a->long_name) < std::string_view(b->long_name);
72 for (
const auto& item : vector_options) {
73 std::string opts_str =
" ";
74 if (item->short_name != 0)
75 opts_str +=
"-" + std::string(1,
static_cast<char>(item->short_name));
76 if (!opts_str.empty() && item->long_name && item->short_name)
78 if (!item->short_name)
81 opts_str +=
"--" + std::string(item->long_name);
82 opts_str =
BOLD(opts_str);
87 std::cout << std::left << std::setw(OPTION_WIDTH + 8) << opts_str;
88 if (item->description !=
nullptr) {
89 std::cout <<
wrapped(item->description, OPTION_WIDTH);
99 return Derived::options_;
virtual void print_help(const std::string command_name, const OptionsCollector *collector) const
bool do_run(const std::string command_name, const ParsedOptions &options, const OptionsCollector *collector=nullptr) override
const CliOption * options() const final
static Config & config()
Gets the singleton configuration instance.
Basic interface for all CLI commands.
virtual bool run(const ParsedOptions &options)=0
Executes the main logic of the command.
virtual std::string_view description() const =0
const std::vector< CliOption > & get_options() const
Configuration management interface.
std::string to_uppercase(const std::string input)
@ UNDERLINE
Underline text.
std::string program_name
Name of the program.
Wrapped wrapped(const std::string &text, size_t spaces, bool use_first_line)
Defines utility functions used across all files.