@@ -648,6 +648,22 @@ class cmdline_processor
648648 flag (int g, std::string_view n, std::string_view d, callback0 h0, callback1 h1, std::string_view s, bool o)
649649 : group{g}, name{n}, description{d}, handler0{h0}, handler1{h1}, synonym{s}, opt_out{o}
650650 { }
651+
652+ auto get_name (bool indicate_short_name = false ) const {
653+ auto n = name.substr (0 , unique_prefix);
654+ if (unique_prefix < std::ssize (name)) {
655+ auto name_length = _as<int >(std::min (name.find (' ' ), name.size ()));
656+ if (indicate_short_name) {
657+ n += " [" ;
658+ }
659+ n += name.substr (unique_prefix, name_length - unique_prefix);
660+ if (indicate_short_name) {
661+ n += " ]" ;
662+ }
663+ n += name.substr (name_length);
664+ }
665+ return n;
666+ }
651667 };
652668 std::vector<flag> flags;
653669 int max_flag_length = 0 ;
@@ -669,13 +685,16 @@ class cmdline_processor
669685 }
670686
671687public:
672- auto flags_starting_with (std::string_view s)
688+ auto flags_starting_with (
689+ std::string_view s,
690+ bool indicate_short_name = true
691+ )
673692 -> std::vector<std::string>
674693 {
675694 auto ret = std::vector<std::string>{};
676- for (auto const & f : flags) {
677- if (f .name .starts_with (s)) {
678- ret.push_back (f. name );
695+ for (auto const & flag : flags) {
696+ if (flag .name .starts_with (s)) {
697+ ret.push_back ( flag. get_name (indicate_short_name) );
679698 }
680699 }
681700 return ret;
@@ -801,14 +820,7 @@ class cmdline_processor
801820 }
802821 }
803822 print (" -" );
804- auto n = flag.name .substr (0 , flag.unique_prefix );
805- if (flag.unique_prefix < std::ssize (flag.name )) {
806- auto name_length = _as<int >(std::min (flag.name .find (' ' ), flag.name .size ()));
807- n += " [" ;
808- n += flag.name .substr (flag.unique_prefix , name_length - flag.unique_prefix );
809- n += " ]" ;
810- n += flag.name .substr (name_length);
811- }
823+ auto n = flag.get_name (true );
812824 if (flag.opt_out ) {
813825 n += " [-]" ;
814826 }
0 commit comments