CLI11 icon indicating copy to clipboard operation
CLI11 copied to clipboard

Subgroup help message: broken indentation

Open AverageBeerEnjoyer opened this issue 5 months ago • 1 comments

Hi, i found bug in help message formatting related to option groups. Looks like this bug relatively new. I have package-distributed CLI11 of version 2.1.0 and there is no such problem, but cant use it due ot lack of some features.

descriptions is not inherit group indentation

// example.cpp
#include "CLI/CLI.hpp"

int main(int argc, char** argv) {
    CLI::App app("test description");
    auto g = app.add_option_group("group", "common group");

    auto g1 = g->add_option_group("subgroup 1", "subgroup 1 description");
    // g1->add_option("-a", "option a");
    
    auto g2 = g->add_option_group("subgroup 2", "subgroup 2 description");
    // g2->add_option("-b", "option b");
    
    auto g3 = g->add_option_group("subgroup 3", "subgroup 3 description");
    // g3->add_option("-c", "option c");

    CLI11_PARSE(app, argc, argv);
}

2.6.2

$ ./example -h
test description


./example [OPTIONS]


OPTIONS:
  -h,     --help              Print this help message and exit
[Option Group: group]
  common group
  
  [Option Group: subgroup 1]
  subgroup 1 description
  
  [Option Group: subgroup 2]
  subgroup 2 description
  
  [Option Group: subgroup 3]
  subgroup 3 description
 

2.1.0

$ ./example -h
test description
Usage: ./example [OPTIONS]

Options:
  -h,--help                   Print this help message and exit
[Option Group: group]
  common group
  [Option Group: subgroup 1]
    subgroup 1 description
  [Option Group: subgroup 2]
    subgroup 2 description
  [Option Group: subgroup 3]
    subgroup 3 description

if uncomment adding option a, indentation of next group breaks down

#include "CLI/CLI.hpp"

int main(int argc, char** argv) {
    CLI::App app("test description");
    auto g = app.add_option_group("group", "common group");

    auto g1 = g->add_option_group("subgroup 1", "subgroup 1 description");
    g1->add_option("-a", "option a");
    
    auto g2 = g->add_option_group("subgroup 2", "subgroup 2 description");
    // g2->add_option("-b", "option b");
    
    auto g3 = g->add_option_group("subgroup 3", "subgroup 3 description");
    // g3->add_option("-c", "option c");

    CLI11_PARSE(app, argc, argv);
}

2.6.2

$ ./example -h
test description


./example [OPTIONS]


OPTIONS:
  -h,     --help              Print this help message and exit
[Option Group: group]
  common group
  
  [Option Group: subgroup 1]
  subgroup 1 description
  
  
OPTIONS:
  -a                          option a
[Option Group: subgroup 2]
  subgroup 2 description
  
  [Option Group: subgroup 3]
  subgroup 3 description
  

2.1.0

$ ./example -h 
test description
Usage: ./example [OPTIONS]

Options:
  -h,--help                   Print this help message and exit
[Option Group: group]
  common group
  [Option Group: subgroup 1]
    subgroup 1 description
    Options:
      -a                          option a
  [Option Group: subgroup 2]
    subgroup 2 description
  [Option Group: subgroup 3]
    subgroup 3 description

AverageBeerEnjoyer avatar Jun 09 '26 07:06 AverageBeerEnjoyer

I wrote a fix for this. I'll add it as a PR tomorrow.

oscarpeer-design avatar Jun 14 '26 11:06 oscarpeer-design