kaycxx-cli
C++ CLI library
Loading...
Searching...
No Matches
app.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
16
17namespace kaycxx::cli {
18
22 std::optional<std::string_view> version = std::nullopt;
23
25 std::optional<std::string_view> description = std::nullopt;
26
28 std::optional<std::string_view> author = std::nullopt;
29
31 std::optional<std::string_view> email = std::nullopt;
32
34 std::optional<std::string_view> bugs = std::nullopt;
35
37 std::optional<std::string_view> copyright = std::nullopt;
38
40 std::optional<std::string_view> license = std::nullopt;
41};
42
50class app final : public command {
51public:
58 explicit app(std::string_view name, app_options options = app_options{});
59
61 app(app const&) = delete;
62
64 app& operator=(app const&) = delete;
65
71 app(app&& other) noexcept;
72
74 ~app() override = default;
75
81 [[nodiscard]] std::optional<std::string> const& version() const noexcept;
82
88 [[nodiscard]] std::optional<std::string> const& author() const noexcept;
89
95 [[nodiscard]] std::optional<std::string> const& email() const noexcept;
96
102 [[nodiscard]] std::optional<std::string> const& bugs() const noexcept;
103
109 [[nodiscard]] std::optional<std::string> const& copyright() const noexcept;
110
116 [[nodiscard]] std::optional<std::string> const& license() const noexcept;
117
130 [[nodiscard]] command_handle command(std::string_view name, std::optional<std::string_view> description = std::nullopt);
131
132private:
133 [[nodiscard]] app const& root() const noexcept override;
134
136 std::optional<std::string> version_;
137
139 std::optional<std::string> author_;
140
142 std::optional<std::string> email_;
143
145 std::optional<std::string> bugs_;
146
148 std::optional<std::string> copyright_;
149
151 std::optional<std::string> license_;
152};
153
154} // namespace kaycxx::cli
Defines and parses a command-line application.
Definition app.hpp:50
std::optional< std::string > const & license() const noexcept
Returns the configured license text.
app(app &&other) noexcept
Moves a command-line application.
std::optional< std::string > const & version() const noexcept
Returns the configured application version.
std::optional< std::string > const & email() const noexcept
Returns the configured author email address.
std::optional< std::string > const & author() const noexcept
Returns the configured author name.
std::optional< std::string > const & bugs() const noexcept
Returns the configured bug-report destination.
app(app const &)=delete
Prevents copying applications.
~app() override=default
Destroys the application and all definitions owned by it.
app(std::string_view name, app_options options=app_options{})
Creates a command-line application.
std::optional< std::string > const & copyright() const noexcept
Returns the configured copyright notice.
app & operator=(app const &)=delete
Prevents copy-assigning applications.
Handle for a registered command.
Definition command_handle.hpp:25
Common base class for an application and its commands.
Definition command.hpp:45
std::string const & name() const noexcept
Returns the command name.
std::optional< std::string > const & description() const noexcept
Returns this command's configured description.
Defines the common command base class.
Optional application metadata.
Definition app.hpp:20
std::optional< std::string_view > version
Application version string used by version output.
Definition app.hpp:22
std::optional< std::string_view > description
Short application description used by generated help output.
Definition app.hpp:25
std::optional< std::string_view > email
Author contact address used by generated version output.
Definition app.hpp:31
std::optional< std::string_view > author
Author name used by generated version output.
Definition app.hpp:28
std::optional< std::string_view > license
License text used by generated version output.
Definition app.hpp:40
std::optional< std::string_view > copyright
Copyright notice used by generated version output.
Definition app.hpp:37
std::optional< std::string_view > bugs
Email address or website URL to which to report bugs to.
Definition app.hpp:34