Skip to content

Commit ee426b0

Browse files
committed
only hiding
1 parent 847d545 commit ee426b0

File tree

2 files changed

+14
-11
lines changed

2 files changed

+14
-11
lines changed

include/ap/argument_group.hpp

Lines changed: 10 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -42,11 +42,15 @@ class argument_group {
4242
public:
4343
argument_group() = delete;
4444

45-
argument_group& description(std::string_view desc) noexcept {
46-
this->_description = desc;
47-
return *this;
48-
}
49-
45+
/**
46+
* @brief Set the `hidden` attribute of the group.
47+
*
48+
* - If set to true, the group will be hidden from the help output.
49+
* - Groups are NOT hidden by default.
50+
*
51+
* @param h The value to set for the attribute (default: true).
52+
* @return Reference to the group instance.
53+
*/
5054
argument_group& hidden(const bool h = true) noexcept {
5155
this->_hidden = h;
5256
return *this;
@@ -99,7 +103,7 @@ class argument_group {
99103

100104
/// Construct a new argument group with the given name.
101105
argument_group(argument_parser& parser, const std::string_view name)
102-
: _parser(&parser), _name(name), _description(std::nullopt) {}
106+
: _parser(&parser), _name(name) {}
103107

104108
/// Add a new argument to this group (called internally by parser).
105109
void _add_argument(arg_ptr_t arg) noexcept {
@@ -108,7 +112,6 @@ class argument_group {
108112

109113
argument_parser* _parser; ///< Pointer to the owning parser.
110114
std::string _name; ///< Name of the group (used in help output).
111-
std::optional<std::string> _description; ///< Description of the group (used in help output).
112115
arg_ptr_vec_t _arguments; ///< A list of arguments that belong to this group.
113116

114117
bool _hidden : 1 = false; ///< The hidden attribute value (default: false).

include/ap/argument_parser.hpp

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -863,8 +863,7 @@ class argument_parser {
863863

864864
this->_print_subparsers(os);
865865
for (const auto& group : this->_argument_groups)
866-
if (not group._hidden)
867-
this->_print_group(os, *group, verbose);
866+
this->_print_group(os, *group, verbose);
868867
}
869868

870869
/**
@@ -1509,6 +1508,9 @@ class argument_parser {
15091508
*/
15101509
void _print_group(std::ostream& os, const argument_group& group, const bool verbose)
15111510
const noexcept {
1511+
if (group._hidden)
1512+
return;
1513+
15121514
auto visible_args = std::views::filter(group._arguments, [](const auto& arg) {
15131515
return not arg->is_hidden();
15141516
});
@@ -1519,8 +1521,6 @@ class argument_parser {
15191521
os << '\n' << group._name << ':';
15201522

15211523
std::vector<std::string_view> group_attrs;
1522-
if (group._description.has_value())
1523-
group_attrs.emplace_back(group._description.value());
15241524
if (group._required)
15251525
group_attrs.emplace_back("required");
15261526
if (group._mutually_exclusive)

0 commit comments

Comments
 (0)