Skip to content

Commit

Permalink
fix help message for --version and --help
Browse files Browse the repository at this point in the history
  • Loading branch information
wx257osn2 committed Jul 23, 2022
1 parent 5706455 commit b1e1e16
Showing 1 changed file with 26 additions and 2 deletions.
28 changes: 26 additions & 2 deletions include/structopt/visitor.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -110,6 +110,8 @@ struct visitor {
os << field << " ";
}

bool has_h = false;
bool has_v = false;
if (flag_field_names.empty() == false) {
os << "\n\nFLAGS:\n";
for (auto &flag : flag_field_names) {
Expand All @@ -124,6 +126,15 @@ struct visitor {
}

os << " -" << flag[0] << ", --" << flag << "\n";

switch (flag[0]) {
case 'h':
has_h = true;
break;
case 'v':
has_v = true;
break;
}
}
} else {
os << "\n";
Expand All @@ -142,8 +153,21 @@ struct visitor {
long_form = option;
}

os << " -" << option[0] << ", --" << long_form << " <" << option << ">"
<< "\n";
if ((has_v && option == "version") || (has_h && option == "help")) {
os << " --" << long_form << " <" << option << ">\n";
} else {
os << " -" << option[0] << ", --" << long_form << " <" << option << ">"
<< "\n";
}

switch (option[0]) {
case 'h':
has_h = true;
break;
case 'v':
has_v = true;
break;
}
}
}

Expand Down

0 comments on commit b1e1e16

Please sign in to comment.