Loading...
Searching...
No Matches
App.hpp
Go to the documentation of this file.
// Copyright (c) 2017-2025, University of Cincinnati, developed by Henry Schreiner
// under NSF AWARD 1414736 and by the respective contributors.
// All rights reserved.
//
// SPDX-License-Identifier: BSD-3-Clause
#pragma once
// IWYU pragma: private, include "CLI/CLI.hpp"
// [CLI11:public_includes:set]
#include <algorithm>
#include <cstdint>
#include <functional>
#include <iostream>
#include <iterator>
#include <memory>
#include <numeric>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
// [CLI11:public_includes:end]
// CLI Library includes
#include "ConfigFwd.hpp"
#include "Error.hpp"
#include "FormatterFwd.hpp"
#include "Macros.hpp"
#include "Option.hpp"
#include "Split.hpp"
#include "StringTools.hpp"
#include "TypeTools.hpp"
namespace CLI {
// [CLI11:app_hpp:verbatim]
#ifndef CLI11_PARSE
#define CLI11_PARSE(app, ...) \
try { \
(app).parse(__VA_ARGS__); \
} catch(const CLI::ParseError &e) { \
return (app).exit(e); \
}
#endif
namespace detail {
enum class Classifier : std::uint8_t {
NONE,
POSITIONAL_MARK,
SHORT,
LONG,
WINDOWS_STYLE,
SUBCOMMAND,
SUBCOMMAND_TERMINATOR
};
struct AppFriend;
} // namespace detail
namespace FailureMessage {
CLI11_INLINE std::string simple(const App *app, const Error &e);
CLI11_INLINE std::string help(const App *app, const Error &e);
} // namespace FailureMessage
enum class config_extras_mode : std::uint8_t { error = 0, ignore, ignore_all, capture };
class App;
using App_p = std::shared_ptr<App>;
namespace detail {
template <typename T, enable_if_t<!std::is_integral<T>::value || (sizeof(T) <= 1U), detail::enabler> = detail::dummy>
Option *default_flag_modifiers(Option *opt) {
return opt->always_capture_default();
}
template <typename T, enable_if_t<std::is_integral<T>::value && (sizeof(T) > 1U), detail::enabler> = detail::dummy>
Option *default_flag_modifiers(Option *opt) {
return opt->multi_option_policy(MultiOptionPolicy::Sum)->default_str("0")->force_callback();
}
} // namespace detail
class Option_group;
class App {
friend Option;
friend detail::AppFriend;
protected:
// This library follows the Google style guide for member names ending in underscores
std::string name_{};
std::string description_{};
bool allow_extras_{false};
config_extras_mode allow_config_extras_{config_extras_mode::ignore};
bool prefix_command_{false};
bool has_automatic_name_{false};
bool required_{false};
bool disabled_{false};
bool pre_parse_called_{false};
bool immediate_callback_{false};
std::function<void(std::size_t)> pre_parse_callback_{};
std::function<void()> parse_complete_callback_{};
std::function<void()> final_callback_{};
OptionDefaults option_defaults_{};
std::vector<Option_p> options_{};
std::string usage_{};
std::function<std::string()> usage_callback_{};
std::string footer_{};
std::function<std::string()> footer_callback_{};
Option *help_ptr_{nullptr};
Option *help_all_ptr_{nullptr};
Option *version_ptr_{nullptr};
std::shared_ptr<FormatterBase> formatter_{new Formatter()};
std::function<std::string(const App *, const Error &e)> failure_message_{FailureMessage::simple};
using missing_t = std::vector<std::pair<detail::Classifier, std::string>>;
missing_t missing_{};
std::vector<Option *> parse_order_{};
std::vector<App *> parsed_subcommands_{};
std::set<App *> exclude_subcommands_{};
std::set<Option *> exclude_options_{};
std::set<App *> need_subcommands_{};
std::set<Option *> need_options_{};
std::vector<App_p> subcommands_{};
bool ignore_case_{false};
bool ignore_underscore_{false};
bool fallthrough_{false};
bool subcommand_fallthrough_{true};
bool allow_windows_style_options_{
#ifdef _WIN32
true
#else
false
#endif
};
bool positionals_at_end_{false};
enum class startup_mode : std::uint8_t { stable, enabled, disabled };
startup_mode default_startup{startup_mode::stable};
bool configurable_{false};
bool validate_positionals_{false};
bool validate_optional_arguments_{false};
bool silent_{false};
bool allow_non_standard_options_{false};
bool allow_prefix_matching_{false};
std::uint32_t parsed_{0U};
std::size_t require_subcommand_min_{0};
std::size_t require_subcommand_max_{0};
std::size_t require_option_min_{0};
std::size_t require_option_max_{0};
App *parent_{nullptr};
std::string group_{"SUBCOMMANDS"};
std::vector<std::string> aliases_{};
Option *config_ptr_{nullptr};
std::shared_ptr<Config> config_formatter_{new ConfigTOML()};
#ifdef _WIN32
std::vector<std::string> normalized_argv_{};
std::vector<char *> normalized_argv_view_{};
#endif
App(std::string app_description, std::string app_name, App *parent);
public:
explicit App(std::string app_description = "", std::string app_name = "")
: App(app_description, app_name, nullptr) {
set_help_flag("-h,--help", "Print this help message and exit");
}
App(const App &) = delete;
App &operator=(const App &) = delete;
virtual ~App() = default;
CLI11_NODISCARD char **ensure_utf8(char **argv);
App *callback(std::function<void()> app_callback) {
if(immediate_callback_) {
parse_complete_callback_ = std::move(app_callback);
} else {
final_callback_ = std::move(app_callback);
}
return this;
}
App *final_callback(std::function<void()> app_callback) {
final_callback_ = std::move(app_callback);
return this;
}
App *parse_complete_callback(std::function<void()> pc_callback) {
parse_complete_callback_ = std::move(pc_callback);
return this;
}
App *preparse_callback(std::function<void(std::size_t)> pp_callback) {
pre_parse_callback_ = std::move(pp_callback);
return this;
}
App *name(std::string app_name = "");
App *alias(std::string app_name);
App *allow_extras(bool allow = true) {
allow_extras_ = allow;
return this;
}
App *required(bool require = true) {
required_ = require;
return this;
}
App *disabled(bool disable = true) {
disabled_ = disable;
return this;
}
App *silent(bool silence = true) {
silent_ = silence;
return this;
}
App *allow_non_standard_option_names(bool allowed = true) {
allow_non_standard_options_ = allowed;
return this;
}
App *allow_subcommand_prefix_matching(bool allowed = true) {
allow_prefix_matching_ = allowed;
return this;
}
App *disabled_by_default(bool disable = true) {
if(disable) {
default_startup = startup_mode::disabled;
} else {
default_startup = (default_startup == startup_mode::enabled) ? startup_mode::enabled : startup_mode::stable;
}
return this;
}
App *enabled_by_default(bool enable = true) {
if(enable) {
default_startup = startup_mode::enabled;
} else {
default_startup =
(default_startup == startup_mode::disabled) ? startup_mode::disabled : startup_mode::stable;
}
return this;
}
App *immediate_callback(bool immediate = true);
App *validate_positionals(bool validate = true) {
validate_positionals_ = validate;
return this;
}
App *validate_optional_arguments(bool validate = true) {
validate_optional_arguments_ = validate;
return this;
}
App *allow_config_extras(bool allow = true) {
if(allow) {
allow_config_extras_ = config_extras_mode::capture;
allow_extras_ = true;
} else {
allow_config_extras_ = config_extras_mode::error;
}
return this;
}
App *allow_config_extras(config_extras_mode mode) {
allow_config_extras_ = mode;
return this;
}
App *prefix_command(bool is_prefix = true) {
prefix_command_ = is_prefix;
return this;
}
App *ignore_case(bool value = true);
App *allow_windows_style_options(bool value = true) {
allow_windows_style_options_ = value;
return this;
}
App *positionals_at_end(bool value = true) {
positionals_at_end_ = value;
return this;
}
App *configurable(bool value = true) {
configurable_ = value;
return this;
}
App *ignore_underscore(bool value = true);
App *formatter(std::shared_ptr<FormatterBase> fmt) {
formatter_ = fmt;
return this;
}
App *formatter_fn(std::function<std::string(const App *, std::string, AppFormatMode)> fmt) {
formatter_ = std::make_shared<FormatterLambda>(fmt);
return this;
}
App *config_formatter(std::shared_ptr<Config> fmt) {
config_formatter_ = fmt;
return this;
}
CLI11_NODISCARD bool parsed() const { return parsed_ > 0; }
OptionDefaults *option_defaults() { return &option_defaults_; }
Option *add_option(std::string option_name,
callback_t option_callback,
std::string option_description = "",
bool defaulted = false,
std::function<std::string()> func = {});
template <typename AssignTo,
typename ConvertTo = AssignTo,
enable_if_t<!std::is_const<ConvertTo>::value, detail::enabler> = detail::dummy>
Option *add_option(std::string option_name,
AssignTo &variable,
std::string option_description = "") {
auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
return detail::lexical_conversion<AssignTo, ConvertTo>(res, variable);
};
Option *opt = add_option(option_name, fun, option_description, false, [&variable]() {
return CLI::detail::checked_to_string<AssignTo, ConvertTo>(variable);
});
opt->type_name(detail::type_name<ConvertTo>());
// these must be actual lvalues since (std::max) sometimes is defined in terms of references and references
// to structs used in the evaluation can be temporary so that would cause issues.
auto Tcount = detail::type_count<AssignTo>::value;
auto XCcount = detail::type_count<ConvertTo>::value;
opt->type_size(detail::type_count_min<ConvertTo>::value, (std::max)(Tcount, XCcount));
opt->expected(detail::expected_count<ConvertTo>::value);
opt->run_callback_for_default();
return opt;
}
template <typename AssignTo, enable_if_t<!std::is_const<AssignTo>::value, detail::enabler> = detail::dummy>
Option *add_option_no_stream(std::string option_name,
AssignTo &variable,
std::string option_description = "") {
auto fun = [&variable](const CLI::results_t &res) { // comment for spacing
return detail::lexical_conversion<AssignTo, AssignTo>(res, variable);
};
Option *opt = add_option(option_name, fun, option_description, false, []() { return std::string{}; });
opt->type_name(detail::type_name<AssignTo>());
opt->type_size(detail::type_count_min<AssignTo>::value, detail::type_count<AssignTo>::value);
opt->expected(detail::expected_count<AssignTo>::value);
opt->run_callback_for_default();
return opt;
}
template <typename ArgType>
Option *add_option_function(std::string option_name,
const std::function<void(const ArgType &)> &func,
std::string option_description = "") {
auto fun = [func](const CLI::results_t &res) {
ArgType variable;
bool result = detail::lexical_conversion<ArgType, ArgType>(res, variable);
if(result) {
func(variable);
}
return result;
};
Option *opt = add_option(option_name, std::move(fun), option_description, false);
opt->type_name(detail::type_name<ArgType>());
opt->type_size(detail::type_count_min<ArgType>::value, detail::type_count<ArgType>::value);
opt->expected(detail::expected_count<ArgType>::value);
return opt;
}
Option *add_option(std::string option_name) {
return add_option(option_name, CLI::callback_t{}, std::string{}, false);
}
template <typename T,
enable_if_t<std::is_const<T>::value && std::is_constructible<std::string, T>::value, detail::enabler> =
detail::dummy>
Option *add_option(std::string option_name, T &option_description) {
return add_option(option_name, CLI::callback_t(), option_description, false);
}
Option *set_help_flag(std::string flag_name = "", const std::string &help_description = "");
Option *set_help_all_flag(std::string help_name = "", const std::string &help_description = "");
Option *set_version_flag(std::string flag_name = "",
const std::string &versionString = "",
const std::string &version_help = "Display program version information and exit");
Option *set_version_flag(std::string flag_name,
std::function<std::string()> vfunc,
const std::string &version_help = "Display program version information and exit");
private:
Option *_add_flag_internal(std::string flag_name, CLI::callback_t fun, std::string flag_description);
public:
Option *add_flag(std::string flag_name) { return _add_flag_internal(flag_name, CLI::callback_t(), std::string{}); }
template <typename T,
enable_if_t<(std::is_const<typename std::remove_reference<T>::type>::value ||
std::is_rvalue_reference<T &&>::value) &&
std::is_constructible<std::string, typename std::remove_reference<T>::type>::value,
detail::enabler> = detail::dummy>
Option *add_flag(std::string flag_name, T &&flag_description) {
return _add_flag_internal(flag_name, CLI::callback_t(), std::forward<T>(flag_description));
}
template <typename T,
enable_if_t<!detail::is_mutable_container<T>::value && !std::is_const<T>::value &&
!std::is_constructible<std::function<void(int)>, T>::value,
detail::enabler> = detail::dummy>
Option *add_flag(std::string flag_name,
T &flag_result,
std::string flag_description = "") {
CLI::callback_t fun = [&flag_result](const CLI::results_t &res) {
using CLI::detail::lexical_cast;
return lexical_cast(res[0], flag_result);
};
auto *opt = _add_flag_internal(flag_name, std::move(fun), std::move(flag_description));
return detail::default_flag_modifiers<T>(opt);
}
template <typename T,
enable_if_t<!std::is_assignable<std::function<void(std::int64_t)> &, T>::value, detail::enabler> =
detail::dummy>
Option *add_flag(std::string flag_name,
std::vector<T> &flag_results,
std::string flag_description = "") {
CLI::callback_t fun = [&flag_results](const CLI::results_t &res) {
bool retval = true;
for(const auto &elem : res) {
using CLI::detail::lexical_cast;
flag_results.emplace_back();
retval &= lexical_cast(elem, flag_results.back());
}
return retval;
};
return _add_flag_internal(flag_name, std::move(fun), std::move(flag_description))
->multi_option_policy(MultiOptionPolicy::TakeAll)
->run_callback_for_default();
}
Option *add_flag_callback(std::string flag_name,
std::function<void(void)> function,
std::string flag_description = "");
Option *add_flag_function(std::string flag_name,
std::function<void(std::int64_t)> function,
std::string flag_description = "");
#ifdef CLI11_CPP14
Option *add_flag(std::string flag_name,
std::function<void(std::int64_t)> function,
std::string flag_description = "") {
return add_flag_function(std::move(flag_name), std::move(function), std::move(flag_description));
}
#endif
Option *set_config(std::string option_name = "",
std::string default_filename = "",
const std::string &help_message = "Read an ini file",
bool config_required = false);
bool remove_option(Option *opt);
template <typename T = Option_group>
T *add_option_group(std::string group_name, std::string group_description = "") {
if(!detail::valid_alias_name_string(group_name)) {
throw IncorrectConstruction("option group names may not contain newlines or null characters");
}
auto option_group = std::make_shared<T>(std::move(group_description), group_name, this);
auto *ptr = option_group.get();
// move to App_p for overload resolution on older gcc versions
App_p app_ptr = std::static_pointer_cast<App>(option_group);
// don't inherit the footer in option groups and clear the help flag by default
app_ptr->footer_ = "";
app_ptr->set_help_flag();
add_subcommand(std::move(app_ptr));
return ptr;
}
App *add_subcommand(std::string subcommand_name = "", std::string subcommand_description = "");
App *add_subcommand(CLI::App_p subcom);
bool remove_subcommand(App *subcom);
App *get_subcommand(const App *subcom) const;
CLI11_NODISCARD App *get_subcommand(std::string subcom) const;
CLI11_NODISCARD App *get_subcommand_no_throw(std::string subcom) const noexcept;
CLI11_NODISCARD App *get_subcommand(int index = 0) const;
CLI::App_p get_subcommand_ptr(App *subcom) const;
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const;
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index = 0) const;
CLI11_NODISCARD App *get_option_group(std::string group_name) const;
CLI11_NODISCARD std::size_t count() const { return parsed_; }
CLI11_NODISCARD std::size_t count_all() const;
App *group(std::string group_name) {
group_ = group_name;
return this;
}
App *require_subcommand() {
require_subcommand_min_ = 1;
require_subcommand_max_ = 0;
return this;
}
App *require_subcommand(int value) {
if(value < 0) {
require_subcommand_min_ = 0;
require_subcommand_max_ = static_cast<std::size_t>(-value);
} else {
require_subcommand_min_ = static_cast<std::size_t>(value);
require_subcommand_max_ = static_cast<std::size_t>(value);
}
return this;
}
App *require_subcommand(std::size_t min, std::size_t max) {
require_subcommand_min_ = min;
require_subcommand_max_ = max;
return this;
}
App *require_option() {
require_option_min_ = 1;
require_option_max_ = 0;
return this;
}
App *require_option(int value) {
if(value < 0) {
require_option_min_ = 0;
require_option_max_ = static_cast<std::size_t>(-value);
} else {
require_option_min_ = static_cast<std::size_t>(value);
require_option_max_ = static_cast<std::size_t>(value);
}
return this;
}
App *require_option(std::size_t min, std::size_t max) {
require_option_min_ = min;
require_option_max_ = max;
return this;
}
App *fallthrough(bool value = true) {
fallthrough_ = value;
return this;
}
App *subcommand_fallthrough(bool value = true) {
subcommand_fallthrough_ = value;
return this;
}
explicit operator bool() const { return parsed_ > 0; }
virtual void pre_callback() {}
//
void clear();
void parse(int argc, const char *const *argv);
void parse(int argc, const wchar_t *const *argv);
private:
template <class CharT> void parse_char_t(int argc, const CharT *const *argv);
public:
void parse(std::string commandline, bool program_name_included = false);
void parse(std::wstring commandline, bool program_name_included = false);
void parse(std::vector<std::string> &args);
void parse(std::vector<std::string> &&args);
void parse_from_stream(std::istream &input);
void failure_message(std::function<std::string(const App *, const Error &e)> function) {
failure_message_ = function;
}
int exit(const Error &e, std::ostream &out = std::cout, std::ostream &err = std::cerr) const;
CLI11_NODISCARD std::size_t count(std::string option_name) const { return get_option(option_name)->count(); }
CLI11_NODISCARD std::vector<App *> get_subcommands() const { return parsed_subcommands_; }
std::vector<const App *> get_subcommands(const std::function<bool(const App *)> &filter) const;
std::vector<App *> get_subcommands(const std::function<bool(App *)> &filter);
bool got_subcommand(const App *subcom) const {
// get subcom needed to verify that this was a real subcommand
return get_subcommand(subcom)->parsed_ > 0;
}
CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const noexcept {
App *sub = get_subcommand_no_throw(subcommand_name);
return (sub != nullptr) ? (sub->parsed_ > 0) : false;
}
App *excludes(Option *opt) {
if(opt == nullptr) {
throw OptionNotFound("nullptr passed");
}
exclude_options_.insert(opt);
return this;
}
App *excludes(App *app) {
if(app == nullptr) {
throw OptionNotFound("nullptr passed");
}
if(app == this) {
throw OptionNotFound("cannot self reference in needs");
}
auto res = exclude_subcommands_.insert(app);
// subcommand exclusion should be symmetric
if(res.second) {
app->exclude_subcommands_.insert(this);
}
return this;
}
App *needs(Option *opt) {
if(opt == nullptr) {
throw OptionNotFound("nullptr passed");
}
need_options_.insert(opt);
return this;
}
App *needs(App *app) {
if(app == nullptr) {
throw OptionNotFound("nullptr passed");
}
if(app == this) {
throw OptionNotFound("cannot self reference in needs");
}
need_subcommands_.insert(app);
return this;
}
bool remove_excludes(Option *opt);
bool remove_excludes(App *app);
bool remove_needs(Option *opt);
bool remove_needs(App *app);
App *usage(std::string usage_string) {
usage_ = std::move(usage_string);
return this;
}
App *usage(std::function<std::string()> usage_function) {
usage_callback_ = std::move(usage_function);
return this;
}
App *footer(std::string footer_string) {
footer_ = std::move(footer_string);
return this;
}
App *footer(std::function<std::string()> footer_function) {
footer_callback_ = std::move(footer_function);
return this;
}
CLI11_NODISCARD std::string config_to_str(bool default_also = false, bool write_description = false) const {
return config_formatter_->to_config(this, default_also, write_description, "");
}
CLI11_NODISCARD std::string help(std::string prev = "", AppFormatMode mode = AppFormatMode::Normal) const;
CLI11_NODISCARD std::string version() const;
CLI11_NODISCARD std::shared_ptr<FormatterBase> get_formatter() const { return formatter_; }
CLI11_NODISCARD std::shared_ptr<Config> get_config_formatter() const { return config_formatter_; }
CLI11_NODISCARD std::shared_ptr<ConfigBase> get_config_formatter_base() const {
// This is safer as a dynamic_cast if we have RTTI, as Config -> ConfigBase
#if CLI11_USE_STATIC_RTTI == 0
return std::dynamic_pointer_cast<ConfigBase>(config_formatter_);
#else
return std::static_pointer_cast<ConfigBase>(config_formatter_);
#endif
}
CLI11_NODISCARD std::string get_description() const { return description_; }
App *description(std::string app_description) {
description_ = std::move(app_description);
return this;
}
std::vector<const Option *> get_options(const std::function<bool(const Option *)> filter = {}) const;
std::vector<Option *> get_options(const std::function<bool(Option *)> filter = {});
CLI11_NODISCARD Option *get_option_no_throw(std::string option_name) noexcept;
CLI11_NODISCARD const Option *get_option_no_throw(std::string option_name) const noexcept;
CLI11_NODISCARD const Option *get_option(std::string option_name) const {
const auto *opt = get_option_no_throw(option_name);
if(opt == nullptr) {
throw OptionNotFound(option_name);
}
return opt;
}
Option *get_option(std::string option_name) {
auto *opt = get_option_no_throw(option_name);
if(opt == nullptr) {
throw OptionNotFound(option_name);
}
return opt;
}
const Option *operator[](const std::string &option_name) const { return get_option(option_name); }
const Option *operator[](const char *option_name) const { return get_option(option_name); }
CLI11_NODISCARD bool get_ignore_case() const { return ignore_case_; }
CLI11_NODISCARD bool get_ignore_underscore() const { return ignore_underscore_; }
CLI11_NODISCARD bool get_fallthrough() const { return fallthrough_; }
CLI11_NODISCARD bool get_subcommand_fallthrough() const { return subcommand_fallthrough_; }
CLI11_NODISCARD bool get_allow_windows_style_options() const { return allow_windows_style_options_; }
CLI11_NODISCARD bool get_positionals_at_end() const { return positionals_at_end_; }
CLI11_NODISCARD bool get_configurable() const { return configurable_; }
CLI11_NODISCARD const std::string &get_group() const { return group_; }
CLI11_NODISCARD std::string get_usage() const {
return (usage_callback_) ? usage_callback_() + '\n' + usage_ : usage_;
}
CLI11_NODISCARD std::string get_footer() const {
return (footer_callback_) ? footer_callback_() + '\n' + footer_ : footer_;
}
CLI11_NODISCARD std::size_t get_require_subcommand_min() const { return require_subcommand_min_; }
CLI11_NODISCARD std::size_t get_require_subcommand_max() const { return require_subcommand_max_; }
CLI11_NODISCARD std::size_t get_require_option_min() const { return require_option_min_; }
CLI11_NODISCARD std::size_t get_require_option_max() const { return require_option_max_; }
CLI11_NODISCARD bool get_prefix_command() const { return prefix_command_; }
CLI11_NODISCARD bool get_allow_extras() const { return allow_extras_; }
CLI11_NODISCARD bool get_required() const { return required_; }
CLI11_NODISCARD bool get_disabled() const { return disabled_; }
CLI11_NODISCARD bool get_silent() const { return silent_; }
CLI11_NODISCARD bool get_allow_non_standard_option_names() const { return allow_non_standard_options_; }
CLI11_NODISCARD bool get_allow_subcommand_prefix_matching() const { return allow_prefix_matching_; }
CLI11_NODISCARD bool get_immediate_callback() const { return immediate_callback_; }
CLI11_NODISCARD bool get_disabled_by_default() const { return (default_startup == startup_mode::disabled); }
CLI11_NODISCARD bool get_enabled_by_default() const { return (default_startup == startup_mode::enabled); }
CLI11_NODISCARD bool get_validate_positionals() const { return validate_positionals_; }
CLI11_NODISCARD bool get_validate_optional_arguments() const { return validate_optional_arguments_; }
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const { return allow_config_extras_; }
Option *get_help_ptr() { return help_ptr_; }
CLI11_NODISCARD const Option *get_help_ptr() const { return help_ptr_; }
CLI11_NODISCARD const Option *get_help_all_ptr() const { return help_all_ptr_; }
Option *get_config_ptr() { return config_ptr_; }
CLI11_NODISCARD const Option *get_config_ptr() const { return config_ptr_; }
Option *get_version_ptr() { return version_ptr_; }
CLI11_NODISCARD const Option *get_version_ptr() const { return version_ptr_; }
App *get_parent() { return parent_; }
CLI11_NODISCARD const App *get_parent() const { return parent_; }
CLI11_NODISCARD const std::string &get_name() const { return name_; }
CLI11_NODISCARD const std::vector<std::string> &get_aliases() const { return aliases_; }
App *clear_aliases() {
aliases_.clear();
return this;
}
CLI11_NODISCARD std::string get_display_name(bool with_aliases = false) const;
CLI11_NODISCARD bool check_name(std::string name_to_check) const;
enum class NameMatch : std::uint8_t { none = 0, exact = 1, prefix = 2 };
CLI11_NODISCARD NameMatch check_name_detail(std::string name_to_check) const;
CLI11_NODISCARD std::vector<std::string> get_groups() const;
CLI11_NODISCARD const std::vector<Option *> &parse_order() const { return parse_order_; }
CLI11_NODISCARD std::vector<std::string> remaining(bool recurse = false) const;
CLI11_NODISCARD std::vector<std::string> remaining_for_passthrough(bool recurse = false) const;
CLI11_NODISCARD std::size_t remaining_size(bool recurse = false) const;
protected:
void _validate() const;
void _configure();
void run_callback(bool final_mode = false, bool suppress_final_callback = false);
CLI11_NODISCARD bool _valid_subcommand(const std::string &current, bool ignore_used = true) const;
CLI11_NODISCARD detail::Classifier _recognize(const std::string &current,
bool ignore_used_subcommands = true) const;
// The parse function is now broken into several parts, and part of process
void _process_config_file();
bool _process_config_file(const std::string &config_file, bool throw_error);
void _process_env();
void _process_callbacks(CallbackPriority priority);
void _process_help_flags(CallbackPriority priority, bool trigger_help = false, bool trigger_all_help = false) const;
void _process_requirements();
void _process();
void _process_extras();
void _process_extras(std::vector<std::string> &args);
void increment_parsed();
void _parse(std::vector<std::string> &args);
void _parse(std::vector<std::string> &&args);
void _parse_stream(std::istream &input);
void _parse_config(const std::vector<ConfigItem> &args);
bool _parse_single_config(const ConfigItem &item, std::size_t level = 0);
bool _add_flag_like_result(Option *op, const ConfigItem &item, const std::vector<std::string> &inputs);
bool _parse_single(std::vector<std::string> &args, bool &positional_only);
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only = false) const;
CLI11_NODISCARD bool _has_remaining_positionals() const;
bool _parse_positional(std::vector<std::string> &args, bool haltOnSubcommand);
CLI11_NODISCARD App *
_find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept;
bool _parse_subcommand(std::vector<std::string> &args);
bool _parse_arg(std::vector<std::string> &args, detail::Classifier current_type, bool local_processing_only);
void _trigger_pre_parse(std::size_t remaining_args);
App *_get_fallthrough_parent();
CLI11_NODISCARD const std::string &_compare_subcommand_names(const App &subcom, const App &base) const;
void _move_to_missing(detail::Classifier val_type, const std::string &val);
public:
void _move_option(Option *opt, App *app);
}; // namespace CLI
class Option_group : public App {
public:
Option_group(std::string group_description, std::string group_name, App *parent)
: App(std::move(group_description), "", parent) {
group(group_name);
// option groups should have automatic fallthrough
if(group_name.empty() || group_name.front() == '+') {
// help will not be used by default in these contexts
set_help_flag("");
set_help_all_flag("");
}
}
using App::add_option;
Option *add_option(Option *opt) {
if(get_parent() == nullptr) {
throw OptionNotFound("Unable to locate the specified option");
}
get_parent()->_move_option(opt, this);
return opt;
}
void add_options(Option *opt) { add_option(opt); }
template <typename... Args> void add_options(Option *opt, Args... args) {
add_option(opt);
add_options(args...);
}
using App::add_subcommand;
App *add_subcommand(App *subcom) {
App_p subc = subcom->get_parent()->get_subcommand_ptr(subcom);
subc->get_parent()->remove_subcommand(subcom);
add_subcommand(std::move(subc));
return subcom;
}
};
CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable);
CLI11_INLINE void TriggerOn(App *trigger_app, std::vector<App *> apps_to_enable);
CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable);
CLI11_INLINE void TriggerOff(App *trigger_app, std::vector<App *> apps_to_enable);
CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement = "");
inline void deprecate_option(App *app, const std::string &option_name, const std::string &replacement = "") {
auto *opt = app->get_option(option_name);
deprecate_option(opt, replacement);
}
inline void deprecate_option(App &app, const std::string &option_name, const std::string &replacement = "") {
auto *opt = app.get_option(option_name);
deprecate_option(opt, replacement);
}
CLI11_INLINE void retire_option(App *app, Option *opt);
CLI11_INLINE void retire_option(App &app, Option *opt);
CLI11_INLINE void retire_option(App *app, const std::string &option_name);
CLI11_INLINE void retire_option(App &app, const std::string &option_name);
namespace detail {
struct AppFriend {
#ifdef CLI11_CPP14
template <typename... Args> static decltype(auto) parse_arg(App *app, Args &&...args) {
return app->_parse_arg(std::forward<Args>(args)...);
}
template <typename... Args> static decltype(auto) parse_subcommand(App *app, Args &&...args) {
return app->_parse_subcommand(std::forward<Args>(args)...);
}
#else
template <typename... Args>
static auto parse_arg(App *app, Args &&...args) ->
typename std::result_of<decltype (&App::_parse_arg)(App, Args...)>::type {
return app->_parse_arg(std::forward<Args>(args)...);
}
template <typename... Args>
static auto parse_subcommand(App *app, Args &&...args) ->
typename std::result_of<decltype (&App::_parse_subcommand)(App, Args...)>::type {
return app->_parse_subcommand(std::forward<Args>(args)...);
}
#endif
static App *get_fallthrough_parent(App *app) { return app->_get_fallthrough_parent(); }
};
} // namespace detail
// [CLI11:app_hpp:end]
} // namespace CLI
#ifndef CLI11_COMPILE
#include "impl/App_inl.hpp" // IWYU pragma: export
#endif
ConfigFwd.hpp
Error.hpp
FormatterFwd.hpp
Macros.hpp
CLI11_INLINE
#define CLI11_INLINE
Definition Macros.hpp:176
CLI11_NODISCARD
#define CLI11_NODISCARD
Definition Macros.hpp:58
Option.hpp
Split.hpp
StringTools.hpp
TypeTools.hpp
CLI::App
Creates a command line program, with very few defaults.
Definition App.hpp:98
CLI::App::_parse_single
bool _parse_single(std::vector< std::string > &args, bool &positional_only)
CLI::App::subcommand_fallthrough_
bool subcommand_fallthrough_
Allow subcommands to fallthrough, so that parent commands can trigger other subcommands after subcomm...
Definition App.hpp:240
CLI::App::ensure_utf8
CLI11_NODISCARD char ** ensure_utf8(char **argv)
Convert the contents of argv to UTF-8. Only does something on Windows, does nothing elsewhere.
CLI::App::operator[]
const Option * operator[](const std::string &option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1113
CLI::App::configurable
App * configurable(bool value=true)
Specify that the subcommand can be triggered by a config file.
Definition App.hpp:498
CLI::App::get_allow_subcommand_prefix_matching
CLI11_NODISCARD bool get_allow_subcommand_prefix_matching() const
Get the status of allowing prefix matching for subcommands.
Definition App.hpp:1183
CLI::App::_process_env
void _process_env()
Get envname options if not yet passed. Runs on all subcommands.
CLI::App::_get_fallthrough_parent
App * _get_fallthrough_parent()
Get the appropriate parent to fallthrough to which is the first one that has a name or the main app.
CLI::App::_process
void _process()
Process callbacks and such.
CLI::App::config_to_str
CLI11_NODISCARD std::string config_to_str(bool default_also=false, bool write_description=false) const
Definition App.hpp:1043
CLI::App::allow_non_standard_options_
bool allow_non_standard_options_
indicator that the subcommand should allow non-standard option arguments, such as -single_dash_flag
Definition App.hpp:272
CLI::App::usage
App * usage(std::function< std::string()> usage_function)
Set usage.
Definition App.hpp:1027
CLI::App::get_enabled_by_default
CLI11_NODISCARD bool get_enabled_by_default() const
Get the status of disabled by default.
Definition App.hpp:1192
CLI::App::config_ptr_
Option * config_ptr_
Pointer to the config option.
Definition App.hpp:306
CLI::App::set_version_flag
Option * set_version_flag(std::string flag_name, std::function< std::string()> vfunc, const std::string &version_help="Display program version information and exit")
Generate the version string through a callback function.
CLI::App::get_allow_non_standard_option_names
CLI11_NODISCARD bool get_allow_non_standard_option_names() const
Get the status of allowing non standard option names.
Definition App.hpp:1180
CLI::App::get_configurable
CLI11_NODISCARD bool get_configurable() const
Check the status of the allow windows style options.
Definition App.hpp:1137
CLI::App::remaining
CLI11_NODISCARD std::vector< std::string > remaining(bool recurse=false) const
This returns the missing options from the current subcommand.
CLI::App::check_name
CLI11_NODISCARD bool check_name(std::string name_to_check) const
CLI::App::parse
void parse(std::string commandline, bool program_name_included=false)
CLI::App::add_option_no_stream
Option * add_option_no_stream(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition App.hpp:582
CLI::App::get_subcommand_ptr
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(int index=0) const
Get an owning pointer to subcommand by index.
CLI::App::get_usage
CLI11_NODISCARD std::string get_usage() const
Generate and return the usage.
Definition App.hpp:1143
CLI::App::get_formatter
CLI11_NODISCARD std::shared_ptr< FormatterBase > get_formatter() const
Access the formatter.
Definition App.hpp:1058
CLI::App::add_option
Option * add_option(std::string option_name)
Add option with no description or variable assignment.
Definition App.hpp:621
CLI::App::subcommand_fallthrough
App * subcommand_fallthrough(bool value=true)
Set subcommand fallthrough, set to true so that subcommands on parents are recognized.
Definition App.hpp:873
CLI::App::config_formatter
App * config_formatter(std::shared_ptr< Config > fmt)
Set the config formatter.
Definition App.hpp:519
CLI::App::remove_excludes
bool remove_excludes(App *app)
Removes a subcommand from the excludes list of this subcommand.
CLI::App::allow_config_extras
App * allow_config_extras(bool allow=true)
ignore extras in config files
Definition App.hpp:458
CLI::App::disabled_by_default
App * disabled_by_default(bool disable=true)
Set the subcommand to be disabled by default, so on clear(), at the start of each parse it is disable...
Definition App.hpp:421
CLI::App::ignore_case
App * ignore_case(bool value=true)
Ignore case. Subcommands inherit value.
CLI::App::_find_subcommand
CLI11_NODISCARD App * _find_subcommand(const std::string &subc_name, bool ignore_disabled, bool ignore_used) const noexcept
CLI::App::_parse_single_config
bool _parse_single_config(const ConfigItem &item, std::size_t level=0)
Fill in a single config option.
CLI::App::_valid_subcommand
CLI11_NODISCARD bool _valid_subcommand(const std::string &current, bool ignore_used=true) const
Check to see if a subcommand is valid. Give up immediately if subcommand max has been reached.
CLI::App::set_version_flag
Option * set_version_flag(std::string flag_name="", const std::string &versionString="", const std::string &version_help="Display program version information and exit")
Set a version flag and version display string, replace the existing one if present.
CLI::App::require_option_min_
std::size_t require_option_min_
Minimum required options (not inheritable!).
Definition App.hpp:287
CLI::App::_parse
void _parse(std::vector< std::string > &args)
Internal parse function.
CLI::App::_parse
void _parse(std::vector< std::string > &&args)
Internal parse function.
CLI::App::NameMatch
NameMatch
enumeration of matching possibilities
Definition App.hpp:1248
CLI::App::NameMatch::none
@ none
Definition App.hpp:1248
CLI::App::NameMatch::exact
@ exact
Definition App.hpp:1248
CLI::App::NameMatch::prefix
@ prefix
Definition App.hpp:1248
CLI::App::silent
App * silent(bool silence=true)
silence the subcommand from showing up in the processed list
Definition App.hpp:404
CLI::App::_process_config_file
bool _process_config_file(const std::string &config_file, bool throw_error)
Read and process a particular configuration file.
CLI::App::clear_aliases
App * clear_aliases()
clear all the aliases of the current App
Definition App.hpp:1235
CLI::App::get_ignore_underscore
CLI11_NODISCARD bool get_ignore_underscore() const
Check the status of ignore_underscore.
Definition App.hpp:1122
CLI::App::_process_callbacks
void _process_callbacks(CallbackPriority priority)
Process callbacks. Runs on all subcommands.
CLI::App::allow_extras
App * allow_extras(bool allow=true)
Remove the error when extras are left over on the command line.
Definition App.hpp:386
CLI::App::fallthrough
App * fallthrough(bool value=true)
Definition App.hpp:867
CLI::App::require_subcommand_max_
std::size_t require_subcommand_max_
Max number of subcommands allowed (parsing stops after this number). 0 is unlimited INHERITABLE.
Definition App.hpp:284
CLI::App::get_config_ptr
Option * get_config_ptr()
Get a pointer to the config option.
Definition App.hpp:1211
CLI::App::subcommands_
std::vector< App_p > subcommands_
Storage for subcommand list.
Definition App.hpp:227
CLI::App::get_allow_extras
CLI11_NODISCARD bool get_allow_extras() const
Get the status of allow extras.
Definition App.hpp:1168
CLI::App::remove_option
bool remove_option(Option *opt)
Removes an option from the App. Takes an option pointer. Returns true if found and removed.
CLI::App::parsed_
std::uint32_t parsed_
Counts the number of times this command/subcommand was parsed.
Definition App.hpp:278
CLI::App::require_subcommand
App * require_subcommand()
The argumentless form of require subcommand requires 1 or more subcommands.
Definition App.hpp:808
CLI::App::count_all
CLI11_NODISCARD std::size_t count_all() const
CLI::App::get_option
Option * get_option(std::string option_name)
Get an option by name (non-const version).
Definition App.hpp:1104
CLI::App::usage_
std::string usage_
Usage to put after program/subcommand description in the help output INHERITABLE.
Definition App.hpp:164
CLI::App::option_defaults_
OptionDefaults option_defaults_
The default values for options, customizable and changeable INHERITABLE.
Definition App.hpp:154
CLI::App::get_version_ptr
CLI11_NODISCARD const Option * get_version_ptr() const
Get a pointer to the version option. (const).
Definition App.hpp:1220
CLI::App::get_groups
CLI11_NODISCARD std::vector< std::string > get_groups() const
Get the groups available directly from this option (in order).
CLI::App::_parse_positional
bool _parse_positional(std::vector< std::string > &args, bool haltOnSubcommand)
CLI::App::set_help_flag
Option * set_help_flag(std::string flag_name="", const std::string &help_description="")
Set a help flag, replace the existing one if present.
CLI::App::get_fallthrough
CLI11_NODISCARD bool get_fallthrough() const
Check the status of fallthrough.
Definition App.hpp:1125
CLI::App::disabled_
bool disabled_
If set to true the subcommand is disabled and cannot be used, ignored for main app.
Definition App.hpp:131
CLI::App::get_prefix_command
CLI11_NODISCARD bool get_prefix_command() const
Get the prefix command status.
Definition App.hpp:1165
CLI::App::add_option
Option * add_option(std::string option_name, AssignTo &variable, std::string option_description="")
Add option for assigning to a variable.
Definition App.hpp:558
CLI::App::get_require_subcommand_max
CLI11_NODISCARD std::size_t get_require_subcommand_max() const
Get the required max subcommand value.
Definition App.hpp:1156
CLI::App::required_
bool required_
If set to true the subcommand is required to be processed and used, ignored for main app.
Definition App.hpp:128
CLI::App::check_name_detail
CLI11_NODISCARD NameMatch check_name_detail(std::string name_to_check) const
CLI::App::operator[]
const Option * operator[](const char *option_name) const
Shortcut bracket operator for getting a pointer to an option.
Definition App.hpp:1116
CLI::App::get_immediate_callback
CLI11_NODISCARD bool get_immediate_callback() const
Get the status of disabled.
Definition App.hpp:1186
CLI::App::get_help_ptr
Option * get_help_ptr()
Get a pointer to the help flag.
Definition App.hpp:1202
CLI::App::require_subcommand
App * require_subcommand(int value)
Definition App.hpp:817
CLI::App::_process_help_flags
void _process_help_flags(CallbackPriority priority, bool trigger_help=false, bool trigger_all_help=false) const
CLI::App::option_defaults
OptionDefaults * option_defaults()
Get the OptionDefault object, to set option defaults.
Definition App.hpp:528
CLI::App::get_subcommand
CLI11_NODISCARD App * get_subcommand(std::string subcom) const
Check to see if a subcommand is part of this command (text version).
CLI::App::_process_extras
void _process_extras()
Throw an error if anything is left over and should not be.
CLI::App::_process_requirements
void _process_requirements()
Verify required options and cross requirements. Subcommands too (only if selected).
CLI::App::footer_
std::string footer_
Footer to put after all options in the help output INHERITABLE.
Definition App.hpp:170
CLI::App::allow_config_extras_
config_extras_mode allow_config_extras_
Definition App.hpp:119
CLI::App::get_footer
CLI11_NODISCARD std::string get_footer() const
Generate and return the footer.
Definition App.hpp:1148
CLI::App::required
App * required(bool require=true)
Remove the error when extras are left over on the command line.
Definition App.hpp:392
CLI::App::version_ptr_
Option * version_ptr_
A pointer to a version flag if there is one.
Definition App.hpp:182
CLI::App::get_help_all_ptr
CLI11_NODISCARD const Option * get_help_all_ptr() const
Get a pointer to the help all flag. (const).
Definition App.hpp:1208
CLI::App::parent_
App * parent_
A pointer to the parent if this is a subcommand.
Definition App.hpp:293
CLI::App::add_flag
Option * add_flag(std::string flag_name, T &&flag_description)
Definition App.hpp:665
CLI::App::exclude_options_
std::set< Option * > exclude_options_
Definition App.hpp:212
CLI::App::group
App * group(std::string group_name)
Changes the group membership.
Definition App.hpp:802
CLI::App::run_callback
void run_callback(bool final_mode=false, bool suppress_final_callback=false)
Internal function to run (App) callback, bottom up.
CLI::App::footer_callback_
std::function< std::string()> footer_callback_
This is a function that generates a footer to put after all other options in help output.
Definition App.hpp:173
CLI::App::App
App(const App &)=delete
CLI::App::get_display_name
CLI11_NODISCARD std::string get_display_name(bool with_aliases=false) const
Get a display name for an app.
CLI::App::parse_complete_callback_
std::function< void()> parse_complete_callback_
This is a function that runs when parsing has finished.
Definition App.hpp:144
CLI::App::get_subcommand_fallthrough
CLI11_NODISCARD bool get_subcommand_fallthrough() const
Check the status of subcommand fallthrough.
Definition App.hpp:1128
CLI::App::pre_callback
virtual void pre_callback()
Definition App.hpp:889
CLI::App::parse
void parse(int argc, const char *const *argv)
CLI::App::add_option_group
T * add_option_group(std::string group_name, std::string group_description="")
creates an option group as part of the given app
Definition App.hpp:738
CLI::App::get_parent
App * get_parent()
Get the parent of this subcommand (or nullptr if main app).
Definition App.hpp:1223
CLI::App::add_flag
Option * add_flag(std::string flag_name)
Add a flag with no description or variable assignment.
Definition App.hpp:655
CLI::App::name_
std::string name_
Subcommand name or program name (from parser if name is empty).
Definition App.hpp:109
CLI::App::parsed_subcommands_
std::vector< App * > parsed_subcommands_
This is a list of the subcommands collected, in order.
Definition App.hpp:205
CLI::App::App
App(std::string app_description="", std::string app_name="")
Create a new program. Pass in the same arguments as main(), along with a help string.
Definition App.hpp:329
CLI::App::get_help_ptr
CLI11_NODISCARD const Option * get_help_ptr() const
Get a pointer to the help flag. (const).
Definition App.hpp:1205
CLI::App::ignore_underscore_
bool ignore_underscore_
If true, the program should ignore underscores INHERITABLE.
Definition App.hpp:233
CLI::App::get_subcommand_ptr
CLI::App_p get_subcommand_ptr(App *subcom) const
Check to see if a subcommand is part of this command and get a shared_ptr to it.
CLI::App::allow_windows_style_options
App * allow_windows_style_options(bool value=true)
Definition App.hpp:486
CLI::App::missing_
missing_t missing_
Definition App.hpp:199
CLI::App::get_validate_positionals
CLI11_NODISCARD bool get_validate_positionals() const
Get the status of validating positionals.
Definition App.hpp:1194
CLI::App::add_option_function
Option * add_option_function(std::string option_name, const std::function< void(const ArgType &)> &func, std::string option_description="")
Add option for a callback of a specific type.
Definition App.hpp:600
CLI::App::allow_prefix_matching_
bool allow_prefix_matching_
indicator to allow subcommands to match with prefix matching
Definition App.hpp:275
CLI::App::version
CLI11_NODISCARD std::string version() const
Displays a version string.
CLI::App::require_subcommand_min_
std::size_t require_subcommand_min_
Minimum required subcommands (not inheritable!).
Definition App.hpp:281
CLI::App::clear
void clear()
Reset the parsed data.
CLI::App::startup_mode
startup_mode
Definition App.hpp:253
CLI::App::startup_mode::disabled
@ disabled
Definition App.hpp:253
CLI::App::startup_mode::enabled
@ enabled
Definition App.hpp:253
CLI::App::startup_mode::stable
@ stable
Definition App.hpp:253
CLI::App::usage
App * usage(std::string usage_string)
Set usage.
Definition App.hpp:1022
CLI::App::allow_subcommand_prefix_matching
App * allow_subcommand_prefix_matching(bool allowed=true)
allow prefix matching for subcommands
Definition App.hpp:416
CLI::App::failure_message_
std::function< std::string(const App *, const Error &e)> failure_message_
The error message printing function INHERITABLE.
Definition App.hpp:188
CLI::App::remove_needs
bool remove_needs(App *app)
Removes a subcommand from the needs list of this subcommand.
CLI::App::failure_message
void failure_message(std::function< std::string(const App *, const Error &e)> function)
Provide a function to print a help message. The function gets access to the App pointer and error.
Definition App.hpp:924
CLI::App::name
App * name(std::string app_name="")
Set a name for the app (empty will use parser to set the name).
CLI::App::has_automatic_name_
bool has_automatic_name_
If set to true the name was automatically generated from the command line vs a user set name.
Definition App.hpp:125
CLI::App::_process_config_file
void _process_config_file()
Read and process a configuration file (main app only).
CLI::App::get_option_group
CLI11_NODISCARD App * get_option_group(std::string group_name) const
Check to see if an option group is part of this App.
CLI::App::get_require_option_max
CLI11_NODISCARD std::size_t get_require_option_max() const
Get the required max option value.
Definition App.hpp:1162
CLI::App::enabled_by_default
App * enabled_by_default(bool enable=true)
Definition App.hpp:432
CLI::App::_process_extras
void _process_extras(std::vector< std::string > &args)
CLI::App::footer
App * footer(std::string footer_string)
Set footer.
Definition App.hpp:1032
CLI::App::needs
App * needs(Option *opt)
Definition App.hpp:987
CLI::App::require_option
App * require_option(int value)
Definition App.hpp:846
CLI::App::get_subcommands
std::vector< App * > get_subcommands(const std::function< bool(App *)> &filter)
CLI::App::~App
virtual ~App()=default
virtual destructor
CLI::App::count
CLI11_NODISCARD std::size_t count(std::string option_name) const
Counts the number of times the given option was passed.
Definition App.hpp:936
CLI::App::options_
std::vector< Option_p > options_
The list of options, stored locally.
Definition App.hpp:157
CLI::App::help_all_ptr_
Option * help_all_ptr_
A pointer to the help all flag if there is one INHERITABLE.
Definition App.hpp:179
CLI::App::validate_optional_arguments_
bool validate_optional_arguments_
If set to true optional vector arguments are validated before assigning INHERITABLE.
Definition App.hpp:265
CLI::App::parse
void parse(std::vector< std::string > &args)
CLI::App::get_subcommand_ptr
CLI11_NODISCARD CLI::App_p get_subcommand_ptr(std::string subcom) const
Check to see if a subcommand is part of this command (text version).
CLI::App::remaining_for_passthrough
CLI11_NODISCARD std::vector< std::string > remaining_for_passthrough(bool recurse=false) const
This returns the missing options in a form ready for processing by another command line program.
CLI::App::add_subcommand
App * add_subcommand(std::string subcommand_name="", std::string subcommand_description="")
Add a subcommand. Inherits INHERITABLE and OptionDefaults, and help flag.
CLI::App::get_option_no_throw
CLI11_NODISCARD const Option * get_option_no_throw(std::string option_name) const noexcept
Get an option by name (noexcept const version).
CLI::App::final_callback_
std::function< void()> final_callback_
This is a function that runs when all processing has completed.
Definition App.hpp:147
CLI::App::add_option
Option * add_option(std::string option_name, callback_t option_callback, std::string option_description="", bool defaulted=false, std::function< std::string()> func={})
CLI::App::require_option
App * require_option()
The argumentless form of require option requires 1 or more options be used.
Definition App.hpp:837
CLI::App::parse
void parse(std::vector< std::string > &&args)
The real work is done here. Expects a reversed vector.
CLI::App::usage_callback_
std::function< std::string()> usage_callback_
This is a function that generates a usage to put after program/subcommand description in help output.
Definition App.hpp:167
CLI::App::preparse_callback
App * preparse_callback(std::function< void(std::size_t)> pp_callback)
Definition App.hpp:374
CLI::App::positionals_at_end_
bool positionals_at_end_
specify that positional arguments come at the end of the argument sequence not inheritable
Definition App.hpp:251
CLI::App::immediate_callback_
bool immediate_callback_
Definition App.hpp:138
CLI::App::add_subcommand
App * add_subcommand(CLI::App_p subcom)
Add a previously created app as a subcommand.
CLI::App::_count_remaining_positionals
CLI11_NODISCARD std::size_t _count_remaining_positionals(bool required_only=false) const
Count the required remaining positional arguments.
CLI::App::get_required
CLI11_NODISCARD bool get_required() const
Get the status of required.
Definition App.hpp:1171
CLI::App::remove_excludes
bool remove_excludes(Option *opt)
Removes an option from the excludes list of this subcommand.
CLI::App::parse_from_stream
void parse_from_stream(std::istream &input)
CLI::App::get_ignore_case
CLI11_NODISCARD bool get_ignore_case() const
Check the status of ignore_case.
Definition App.hpp:1119
CLI::App::parse_complete_callback
App * parse_complete_callback(std::function< void()> pc_callback)
Definition App.hpp:367
CLI::App::configurable_
bool configurable_
if set to true the subcommand can be triggered via configuration files INHERITABLE
Definition App.hpp:259
CLI::App::got_subcommand
CLI11_NODISCARD bool got_subcommand(std::string subcommand_name) const noexcept
Check with name instead of pointer to see if subcommand was selected.
Definition App.hpp:957
CLI::App::formatter_fn
App * formatter_fn(std::function< std::string(const App *, std::string, AppFormatMode)> fmt)
Set the help formatter.
Definition App.hpp:513
CLI::App::get_aliases
CLI11_NODISCARD const std::vector< std::string > & get_aliases() const
Get the aliases of the current app.
Definition App.hpp:1232
CLI::App::description
App * description(std::string app_description)
Set the description of the app.
Definition App.hpp:1077
CLI::App::get_config_formatter_base
CLI11_NODISCARD std::shared_ptr< ConfigBase > get_config_formatter_base() const
Access the config formatter as a configBase pointer.
Definition App.hpp:1064
CLI::App::set_help_all_flag
Option * set_help_all_flag(std::string help_name="", const std::string &help_description="")
Set a help all flag, replaced the existing one if present.
CLI::App::description_
std::string description_
Description of the current program/subcommand.
Definition App.hpp:112
CLI::App::_parse_arg
bool _parse_arg(std::vector< std::string > &args, detail::Classifier current_type, bool local_processing_only)
CLI::App::excludes
App * excludes(App *app)
Sets excluded subcommands for the subcommand.
Definition App.hpp:972
CLI::App::App
App(std::string app_description, std::string app_name, App *parent)
Special private constructor for subcommand.
CLI::App::remove_needs
bool remove_needs(Option *opt)
Removes an option from the needs list of this subcommand.
CLI::App::_move_option
void _move_option(Option *opt, App *app)
function that could be used by subclasses of App to shift options around into subcommands
CLI::App::allow_non_standard_option_names
App * allow_non_standard_option_names(bool allowed=true)
allow non standard option names
Definition App.hpp:410
CLI::App::exit
int exit(const Error &e, std::ostream &out=std::cout, std::ostream &err=std::cerr) const
Print a nice error message and return the exit code.
CLI::App::get_positionals_at_end
CLI11_NODISCARD bool get_positionals_at_end() const
Check the status of the allow windows style options.
Definition App.hpp:1134
CLI::App::get_subcommands
std::vector< const App * > get_subcommands(const std::function< bool(const App *)> &filter) const
CLI::App::get_version_ptr
Option * get_version_ptr()
Get a pointer to the version option.
Definition App.hpp:1217
CLI::App::get_require_option_min
CLI11_NODISCARD std::size_t get_require_option_min() const
Get the required min option value.
Definition App.hpp:1159
CLI::App::require_option_max_
std::size_t require_option_max_
Max number of options allowed. 0 is unlimited (not inheritable).
Definition App.hpp:290
CLI::App::get_subcommand
CLI11_NODISCARD App * get_subcommand(int index=0) const
Get a pointer to subcommand by index.
CLI::App::missing_t
std::vector< std::pair< detail::Classifier, std::string > > missing_t
Definition App.hpp:194
CLI::App::get_disabled
CLI11_NODISCARD bool get_disabled() const
Get the status of disabled.
Definition App.hpp:1174
CLI::App::add_flag_callback
Option * add_flag_callback(std::string flag_name, std::function< void(void)> function, std::string flag_description="")
Add option for callback that is triggered with a true flag and takes no arguments.
CLI::App::get_allow_windows_style_options
CLI11_NODISCARD bool get_allow_windows_style_options() const
Check the status of the allow windows style options.
Definition App.hpp:1131
CLI::App::get_options
std::vector< const Option * > get_options(const std::function< bool(const Option *)> filter={}) const
Get the list of options (user facing function, so returns raw pointers), has optional filter function...
CLI::App::_recognize
CLI11_NODISCARD detail::Classifier _recognize(const std::string &current, bool ignore_used_subcommands=true) const
Selects a Classifier enum based on the type of the current argument.
CLI::App::aliases_
std::vector< std::string > aliases_
Alias names for the subcommand.
Definition App.hpp:299
CLI::App::_parse_stream
void _parse_stream(std::istream &input)
Internal function to parse a stream.
CLI::App::parsed
CLI11_NODISCARD bool parsed() const
Check to see if this subcommand was parsed, true only if received on command line.
Definition App.hpp:525
CLI::App::exclude_subcommands_
std::set< App * > exclude_subcommands_
this is a list of subcommands that are exclusionary to this one
Definition App.hpp:208
CLI::App::get_disabled_by_default
CLI11_NODISCARD bool get_disabled_by_default() const
Get the status of disabled by default.
Definition App.hpp:1189
CLI::App::add_flag
Option * add_flag(std::string flag_name, std::vector< T > &flag_results, std::string flag_description="")
Vector version to capture multiple flags.
Definition App.hpp:691
CLI::App::count
CLI11_NODISCARD std::size_t count() const
Definition App.hpp:795
CLI::App::ignore_case_
bool ignore_case_
If true, the program name is not case-sensitive INHERITABLE.
Definition App.hpp:230
CLI::App::get_group
CLI11_NODISCARD const std::string & get_group() const
Get the group of this subcommand.
Definition App.hpp:1140
CLI::App::set_config
Option * set_config(std::string option_name="", std::string default_filename="", const std::string &help_message="Read an ini file", bool config_required=false)
Set a configuration ini file option, or clear it if no name passed.
CLI::App::silent_
bool silent_
Definition App.hpp:269
CLI::App::get_parent
CLI11_NODISCARD const App * get_parent() const
Get the parent of this subcommand (or nullptr if main app) (const version).
Definition App.hpp:1226
CLI::App::pre_parse_callback_
std::function< void(std::size_t)> pre_parse_callback_
This is a function that runs prior to the start of parsing.
Definition App.hpp:141
CLI::App::final_callback
App * final_callback(std::function< void()> app_callback)
Definition App.hpp:360
CLI::App::group_
std::string group_
The group membership INHERITABLE.
Definition App.hpp:296
CLI::App::remaining_size
CLI11_NODISCARD std::size_t remaining_size(bool recurse=false) const
This returns the number of remaining options, minus the – separator.
CLI::App::pre_parse_called_
bool pre_parse_called_
Flag indicating that the pre_parse_callback has been triggered.
Definition App.hpp:134
CLI::App::validate_positionals
App * validate_positionals(bool validate=true)
Set the subcommand to validate positional arguments before assigning.
Definition App.hpp:446
CLI::App::help_ptr_
Option * help_ptr_
A pointer to the help flag if there is one INHERITABLE.
Definition App.hpp:176
CLI::App::footer
App * footer(std::function< std::string()> footer_function)
Set footer.
Definition App.hpp:1037
CLI::App::excludes
App * excludes(Option *opt)
Sets excluded options for the subcommand.
Definition App.hpp:963
CLI::App::ignore_underscore
App * ignore_underscore(bool value=true)
Ignore underscore. Subcommands inherit value.
CLI::App::get_config_formatter
CLI11_NODISCARD std::shared_ptr< Config > get_config_formatter() const
Access the config formatter.
Definition App.hpp:1061
CLI::App::parse
void parse(std::wstring commandline, bool program_name_included=false)
CLI::App::_configure
void _configure()
CLI::App::parse
void parse(int argc, const wchar_t *const *argv)
CLI::App::get_subcommands
CLI11_NODISCARD std::vector< App * > get_subcommands() const
Definition App.hpp:940
CLI::App::remove_subcommand
bool remove_subcommand(App *subcom)
Removes a subcommand from the App. Takes a subcommand pointer. Returns true if found and removed.
CLI::App::_add_flag_like_result
bool _add_flag_like_result(Option *op, const ConfigItem &item, const std::vector< std::string > &inputs)
store the results for a flag like option
CLI::App::get_subcommand
App * get_subcommand(const App *subcom) const
CLI::App::got_subcommand
bool got_subcommand(const App *subcom) const
Check to see if given subcommand was selected.
Definition App.hpp:951
CLI::App::get_allow_config_extras
CLI11_NODISCARD config_extras_mode get_allow_config_extras() const
Get the status of allow extras.
Definition App.hpp:1199
CLI::App::_has_remaining_positionals
CLI11_NODISCARD bool _has_remaining_positionals() const
Count the required remaining positional arguments.
CLI::App::positionals_at_end
App * positionals_at_end(bool value=true)
Specify that the positional arguments are only at the end of the sequence.
Definition App.hpp:492
CLI::App::help
CLI11_NODISCARD std::string help(std::string prev="", AppFormatMode mode=AppFormatMode::Normal) const
CLI::App::fallthrough_
bool fallthrough_
Definition App.hpp:237
CLI::App::need_options_
std::set< Option * > need_options_
Definition App.hpp:220
CLI::App::get_validate_optional_arguments
CLI11_NODISCARD bool get_validate_optional_arguments() const
Get the status of validating optional vector arguments.
Definition App.hpp:1196
CLI::App::alias
App * alias(std::string app_name)
Set an alias for the app.
CLI::App::get_silent
CLI11_NODISCARD bool get_silent() const
Get the status of silence.
Definition App.hpp:1177
CLI::App::need_subcommands_
std::set< App * > need_subcommands_
Definition App.hpp:216
CLI::App::validate_optional_arguments
App * validate_optional_arguments(bool validate=true)
Set the subcommand to validate optional vector arguments before assigning.
Definition App.hpp:452
CLI::App::prefix_command_
bool prefix_command_
If true, cease processing on an unrecognized option (implies allow_extras) INHERITABLE.
Definition App.hpp:122
CLI::App::formatter
App * formatter(std::shared_ptr< FormatterBase > fmt)
Set the help formatter.
Definition App.hpp:507
CLI::App::parse_order_
std::vector< Option * > parse_order_
This is a list of pointers to options with the original parse order.
Definition App.hpp:202
CLI::App::add_option
Option * add_option(std::string option_name, T &option_description)
Add option with description but with no variable assignment or callback.
Definition App.hpp:629
CLI::App::_trigger_pre_parse
void _trigger_pre_parse(std::size_t remaining_args)
Trigger the pre_parse callback if needed.
CLI::App::prefix_command
App * prefix_command(bool is_prefix=true)
Definition App.hpp:476
CLI::App::parse_order
CLI11_NODISCARD const std::vector< Option * > & parse_order() const
This gets a vector of pointers with the original parse order.
Definition App.hpp:1259
CLI::App::validate_positionals_
bool validate_positionals_
If set to true positional options are validated before assigning INHERITABLE.
Definition App.hpp:262
CLI::App::_validate
void _validate() const
CLI::App::default_startup
startup_mode default_startup
Definition App.hpp:256
CLI::App::allow_config_extras
App * allow_config_extras(config_extras_mode mode)
ignore extras in config files
Definition App.hpp:469
CLI::App::add_flag
Option * add_flag(std::string flag_name, T &flag_result, std::string flag_description="")
Definition App.hpp:675
CLI::App::increment_parsed
void increment_parsed()
Internal function to recursively increment the parsed counter on the current app as well unnamed subc...
CLI::App::allow_extras_
bool allow_extras_
If true, allow extra arguments (ie, don't throw an error). INHERITABLE.
Definition App.hpp:115
CLI::App::get_description
CLI11_NODISCARD std::string get_description() const
Get the app or subcommand description.
Definition App.hpp:1074
CLI::App::operator=
App & operator=(const App &)=delete
CLI::App::require_option
App * require_option(std::size_t min, std::size_t max)
Definition App.hpp:859
CLI::App::immediate_callback
App * immediate_callback(bool immediate=true)
Set the subcommand callback to be executed immediately on subcommand completion.
CLI::App::get_options
std::vector< Option * > get_options(const std::function< bool(Option *)> filter={})
Non-const version of the above.
CLI::App::get_require_subcommand_min
CLI11_NODISCARD std::size_t get_require_subcommand_min() const
Get the required min subcommand value.
Definition App.hpp:1153
CLI::App::add_flag_function
Option * add_flag_function(std::string flag_name, std::function< void(std::int64_t)> function, std::string flag_description="")
Add option for callback with an integer value.
CLI::App::get_config_ptr
CLI11_NODISCARD const Option * get_config_ptr() const
Get a pointer to the config option. (const).
Definition App.hpp:1214
CLI::App::_parse_subcommand
bool _parse_subcommand(std::vector< std::string > &args)
CLI::App::_parse_config
void _parse_config(const std::vector< ConfigItem > &args)
CLI::App::_compare_subcommand_names
CLI11_NODISCARD const std::string & _compare_subcommand_names(const App &subcom, const App &base) const
Helper function to run through all possible comparisons of subcommand names to check there is no over...
CLI::App::get_name
CLI11_NODISCARD const std::string & get_name() const
Get the name of the current app.
Definition App.hpp:1229
CLI::App::disabled
App * disabled(bool disable=true)
Disable the subcommand or option group.
Definition App.hpp:398
CLI::App::callback
App * callback(std::function< void()> app_callback)
Definition App.hpp:349
CLI::App::formatter_
std::shared_ptr< FormatterBase > formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer).
Definition App.hpp:185
CLI::App::needs
App * needs(App *app)
Definition App.hpp:995
CLI::App::require_subcommand
App * require_subcommand(std::size_t min, std::size_t max)
Definition App.hpp:830
CLI::App::get_option
CLI11_NODISCARD const Option * get_option(std::string option_name) const
Get an option by name.
Definition App.hpp:1095
CLI::App::allow_windows_style_options_
bool allow_windows_style_options_
Allow '/' for options for Windows like options. Defaults to true on Windows, false otherwise....
Definition App.hpp:243
CLI::App::get_subcommand_no_throw
CLI11_NODISCARD App * get_subcommand_no_throw(std::string subcom) const noexcept
CLI::App::_move_to_missing
void _move_to_missing(detail::Classifier val_type, const std::string &val)
Helper function to place extra values in the most appropriate position.
CLI::App::config_formatter_
std::shared_ptr< Config > config_formatter_
This is the formatter for help printing. Default provided. INHERITABLE (same pointer).
Definition App.hpp:309
CLI::App::get_option_no_throw
CLI11_NODISCARD Option * get_option_no_throw(std::string option_name) noexcept
Get an option by name (noexcept non-const version).
CLI::Error
All errors derive from this one.
Definition Error.hpp:73
CLI::Formatter
Definition FormatterFwd.hpp:167
CLI::OptionBase::always_capture_default
CRTP * always_capture_default(bool value=true)
Definition Option.hpp:126
CLI::OptionDefaults
Definition Option.hpp:216
CLI::Option_group::add_subcommand
App * add_subcommand(App *subcom)
Add an existing subcommand to be a member of an option_group.
Definition App.hpp:1429
CLI::Option_group::add_option
Option * add_option(Option *opt)
Add an existing option to the Option_group.
Definition App.hpp:1413
CLI::Option_group::Option_group
Option_group(std::string group_description, std::string group_name, App *parent)
Definition App.hpp:1401
CLI::Option_group::add_options
void add_options(Option *opt, Args... args)
Add a bunch of options to the group.
Definition App.hpp:1423
CLI::Option_group::add_options
void add_options(Option *opt)
Add an existing option to the Option_group.
Definition App.hpp:1421
CLI::Option
Definition Option.hpp:259
CLI::Option::type_name
Option * type_name(std::string typeval)
Set a custom option typestring.
Definition Option.hpp:779
CLI::Option::multi_option_policy
Option * multi_option_policy(MultiOptionPolicy value=MultiOptionPolicy::Throw)
Take the last argument if given multiple times (or another policy).
CLI::Option::expected
Option * expected(int value)
Set the number of expected arguments.
CLI::Option::count
CLI11_NODISCARD std::size_t count() const
Count the total number of times an option was passed.
Definition Option.hpp:389
CLI::Option::run_callback_for_default
Option * run_callback_for_default(bool value=true)
Definition Option.hpp:439
CLI::Option::type_size
Option * type_size(int option_type_size)
Set a custom option size.
CLI::Option::default_str
Option * default_str(std::string val)
Set the default value string representation (does not change the contained value).
Definition Option.hpp:808
CLI::Option::force_callback
Option * force_callback(bool value=true)
Set the value of force_callback.
Definition Option.hpp:430
CLI::FailureMessage
Definition App.hpp:61
CLI::FailureMessage::help
CLI11_INLINE std::string help(const App *app, const Error &e)
Printout the full help string on error (if this fn is set, the old default for CLI11).
CLI::FailureMessage::simple
CLI11_INLINE std::string simple(const App *app, const Error &e)
Printout a clean, simple message on error (the default in CLI11 1.5+).
CLI::detail
Definition App.hpp:48
CLI::detail::dummy
constexpr enabler dummy
An instance to use in EnableIf.
Definition TypeTools.hpp:39
CLI::detail::Classifier
Classifier
Definition App.hpp:49
CLI::detail::Classifier::WINDOWS_STYLE
@ WINDOWS_STYLE
Definition App.hpp:54
CLI::detail::Classifier::POSITIONAL_MARK
@ POSITIONAL_MARK
Definition App.hpp:51
CLI::detail::Classifier::SHORT
@ SHORT
Definition App.hpp:52
CLI::detail::Classifier::SUBCOMMAND_TERMINATOR
@ SUBCOMMAND_TERMINATOR
Definition App.hpp:56
CLI::detail::Classifier::NONE
@ NONE
Definition App.hpp:50
CLI::detail::Classifier::LONG
@ LONG
Definition App.hpp:53
CLI::detail::Classifier::SUBCOMMAND
@ SUBCOMMAND
Definition App.hpp:55
CLI::detail::checked_to_string
auto checked_to_string(T &&value) -> decltype(to_string(std::forward< T >(value)))
special template overload
Definition TypeTools.hpp:456
CLI::detail::default_flag_modifiers
Option * default_flag_modifiers(Option *opt)
helper functions for adding in appropriate flag modifiers for add_flag
Definition App.hpp:81
CLI::detail::enabler
enabler
Simple empty scoped class.
Definition TypeTools.hpp:36
CLI::detail::valid_alias_name_string
bool valid_alias_name_string(const std::string &str)
Verify an app name.
Definition StringTools.hpp:167
CLI
Definition App.hpp:36
CLI::App_p
std::shared_ptr< App > App_p
Definition App.hpp:75
CLI::ConfigTOML
ConfigBase ConfigTOML
the default Config is the TOML file format
Definition ConfigFwd.hpp:188
CLI::deprecate_option
CLI11_INLINE void deprecate_option(Option *opt, const std::string &replacement="")
Helper function to mark an option as deprecated.
CLI::enable_if_t
typename std::enable_if< B, T >::type enable_if_t
Definition TypeTools.hpp:47
CLI::CallbackPriority
CallbackPriority
enumeration for the callback priority
Definition Option.hpp:54
CLI::retire_option
CLI11_INLINE void retire_option(App *app, Option *opt)
Helper function to mark an option as retired.
CLI::ExitCodes::IncorrectConstruction
@ IncorrectConstruction
Definition Error.hpp:46
CLI::ExitCodes::OptionNotFound
@ OptionNotFound
Definition Error.hpp:59
CLI::MultiOptionPolicy::TakeAll
@ TakeAll
just get all the passed argument regardless
Definition Option.hpp:48
CLI::MultiOptionPolicy::Sum
@ Sum
sum all the arguments together if numerical or concatenate directly without delimiter
Definition Option.hpp:49
CLI::TriggerOff
CLI11_INLINE void TriggerOff(App *trigger_app, App *app_to_enable)
Helper function to disable one option group/subcommand when another is used.
CLI::TriggerOn
CLI11_INLINE void TriggerOn(App *trigger_app, App *app_to_enable)
Helper function to enable one option group/subcommand when another is used.
CLI::config_extras_mode
config_extras_mode
enumeration of modes of how to deal with extras in config files
Definition App.hpp:71
CLI::config_extras_mode::ignore
@ ignore
Definition App.hpp:71
CLI::config_extras_mode::error
@ error
Definition App.hpp:71
CLI::config_extras_mode::capture
@ capture
Definition App.hpp:71
CLI::config_extras_mode::ignore_all
@ ignore_all
Definition App.hpp:71
CLI::callback_t
std::function< bool(const results_t &)> callback_t
callback function definition
Definition Option.hpp:33
CLI::AppFormatMode
AppFormatMode
Definition FormatterFwd.hpp:32
CLI::AppFormatMode::Normal
@ Normal
The normal, detailed help.
Definition FormatterFwd.hpp:33
CLI::results_t
std::vector< std::string > results_t
Definition Option.hpp:31
CLI::ConfigItem
Holds values to load into Options.
Definition ConfigFwd.hpp:29
CLI::detail::AppFriend
This class is simply to allow tests access to App's protected functions.
Definition App.hpp:1478
CLI::detail::AppFriend::parse_subcommand
static auto parse_subcommand(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_subcommand)(App, Args...)>::type
Wrap _parse_subcommand, perfectly forward arguments and return.
Definition App.hpp:1500
CLI::detail::AppFriend::get_fallthrough_parent
static App * get_fallthrough_parent(App *app)
Wrap the fallthrough parent function to make sure that is working correctly.
Definition App.hpp:1506
CLI::detail::AppFriend::parse_arg
static auto parse_arg(App *app, Args &&...args) -> typename std::result_of< decltype(&App::_parse_arg)(App, Args...)>::type
Wrap _parse_short, perfectly forward arguments and return.
Definition App.hpp:1493
CLI::detail::type_count::value
static const int value
Definition TypeTools.hpp:505