kaycxx-cli
C++ CLI library
Loading...
Searching...
No Matches
switch_base.hpp
Go to the documentation of this file.
1// SPDX-FileCopyrightText: 2026 Klaus Reimer <k@ailis.de>
2// SPDX-License-Identifier: MIT
3
9#pragma once
10
11#include <optional>
12#include <string>
13#include <string_view>
14
15namespace kaycxx::cli {
16
23public:
30 explicit switch_base(std::string_view name, std::optional<std::string_view> description = std::nullopt);
31
39 explicit switch_base(std::string_view name, char alias, std::optional<std::string_view> description = std::nullopt);
40
42 virtual ~switch_base() = default;
43
49 [[nodiscard]] std::string const& name() const noexcept;
50
57
64
67
74
80 [[nodiscard]] virtual std::string usage() const = 0;
81
88
91 std::string name_;
92
94 std::optional<char> alias_;
95
97 std::optional<std::string> description_;
98
100 bool action_ = false;
101};
102
103} // namespace kaycxx::cli
Handle for a registered option.
Definition option_handle.hpp:25
Common base class for command line switches.
Definition switch_base.hpp:22
virtual bool expects_value() const noexcept=0
Checks whether this switch expects a value.
std::optional< std::string > const & description() const noexcept
Returns the switch description.
virtual ~switch_base()=default
Destroys the switch definition.
std::optional< char > alias() const noexcept
Returns the short switch alias.
bool is_action() const noexcept
Checks whether this switch is a command action.
virtual std::string usage() const =0
Returns generated help usage for this switch.
switch_base(std::string_view name, std::optional< std::string_view > description=std::nullopt)
Creates a switch without a short alias.
switch_base(std::string_view name, char alias, std::optional< std::string_view > description=std::nullopt)
Creates a switch with a short alias.
void mark_as_action() noexcept
Marks this switch as a mutually exclusive command action.
std::string const & name() const noexcept
Returns the long switch name.