@@ -648,6 +648,22 @@ class cmdline_processor
648
648
flag (int g, std::string_view n, std::string_view d, callback0 h0, callback1 h1, std::string_view s, bool o)
649
649
: group{g}, name{n}, description{d}, handler0{h0}, handler1{h1}, synonym{s}, opt_out{o}
650
650
{ }
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
+ }
651
667
};
652
668
std::vector<flag> flags;
653
669
int max_flag_length = 0 ;
@@ -669,13 +685,16 @@ class cmdline_processor
669
685
}
670
686
671
687
public:
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
+ )
673
692
-> std::vector<std::string>
674
693
{
675
694
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) );
679
698
}
680
699
}
681
700
return ret;
@@ -801,14 +820,7 @@ class cmdline_processor
801
820
}
802
821
}
803
822
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 );
812
824
if (flag.opt_out ) {
813
825
n += " [-]" ;
814
826
}
0 commit comments