CPP-ARGON 4.0.0
Command-Line Argument Parser for C++20
Loading...
Searching...
No Matches
argument_group.hpp
Go to the documentation of this file.
1// Copyright (c) 2023-2026 Jakub Musiał
2// This file is part of the CPP-ARGON project (https://github.com/SpectraL519/cpp-argon).
3// Licensed under the MIT License. See the LICENSE file in the project root for full license information.
4
6
7#pragma once
8
10
11#include <memory>
12
13namespace argon {
14
42public:
43 argument_group() = delete;
44
54 argument_group& hidden(const bool h = true) noexcept {
55 this->_hidden = h;
56 return *this;
57 }
58
69 argument_group& required(const bool r = true) noexcept {
70 this->_required = r;
71 return *this;
72 }
73
84 argument_group& mutually_exclusive(const bool me = true) noexcept {
85 this->_mutually_exclusive = me;
86 return *this;
87 }
88
89 friend class argument_parser;
90
91private:
92 using arg_ptr_t = std::shared_ptr<detail::argument_base>;
93 using arg_ptr_vec_t = std::vector<arg_ptr_t>;
94
100 static std::unique_ptr<argument_group> create(argument_parser& parser, std::string_view name) {
101 return std::unique_ptr<argument_group>(new argument_group(parser, name));
102 }
103
105 argument_group(argument_parser& parser, const std::string_view name)
106 : _parser(&parser), _name(name) {}
107
109 void _add_argument(arg_ptr_t arg) noexcept {
110 this->_arguments.emplace_back(std::move(arg));
111 }
112
114 std::string _name;
116
117 bool _hidden : 1 = false;
118 bool _required : 1 = false;
120 false;
121};
122
123} // namespace argon
Defines the base argument class and common utility.
Represents a group of arguments.
argument_group & required(const bool r=true) noexcept
Set the required attribute of the group.
std::vector< arg_ptr_t > arg_ptr_vec_t
The argument pointer list type alias.
argument_group & hidden(const bool h=true) noexcept
Set the hidden attribute of the group.
argument_parser * _parser
Pointer to the owning parser.
bool _required
The required attribute value (default: false).
bool _hidden
The hidden attribute value (default: false).
std::string _name
Name of the group (used in help output).
arg_ptr_vec_t _arguments
A list of arguments that belong to this group.
static std::unique_ptr< argument_group > create(argument_parser &parser, std::string_view name)
Factory method to create an argument group.
std::shared_ptr< detail::argument_base > arg_ptr_t
The argument pointer type alias.
bool _mutually_exclusive
The mutually exclusive attribute value (default: false).
argument_group(argument_parser &parser, const std::string_view name)
Construct a new argument group with the given name.
argument_group & mutually_exclusive(const bool me=true) noexcept
Set the mutually_exclusive attribute of the group.
void _add_argument(arg_ptr_t arg) noexcept
Add a new argument to this group (called internally by parser).
The main argument parser class.