1- use crate :: tr ;
1+ use crate :: i18n :: locale_keys :: cli :: * ;
22use crate :: info:: langs:: language:: { Language , LanguageType } ;
33use crate :: info:: utils:: info_field:: InfoType ;
4+ use crate :: tr;
45use crate :: ui:: printer:: SerializationFormat ;
56use anyhow:: Result ;
6- use clap:: builder:: { PossibleValuesParser , Styles } ;
77use clap:: builder:: TypedValueParser as _;
8+ use clap:: builder:: { PossibleValuesParser , Styles } ;
89use clap:: { value_parser, Args , Command , Parser , ValueHint } ;
910use clap_complete:: { generate, Generator , Shell } ;
1011use num_format:: CustomFormat ;
@@ -17,11 +18,27 @@ use std::io;
1718use std:: path:: PathBuf ;
1819use std:: str:: FromStr ;
1920use strum:: IntoEnumIterator ;
20- use crate :: i18n:: locale_keys:: cli:: * ;
2121
2222const COLOR_RESOLUTIONS : [ & str ; 5 ] = [ "16" , "32" , "64" , "128" , "256" ] ;
2323pub const NO_BOTS_DEFAULT_REGEX_PATTERN : & str = r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]" ;
2424
25+ // TODO: check if short help requested more efficiently
26+ use std:: sync:: LazyLock ;
27+ static IS_SHORT : LazyLock < bool > = LazyLock :: new ( || {
28+ let args = std:: env:: args ( ) ;
29+ let mut v = false ;
30+ for value in args {
31+ if value == "-h" {
32+ v = true ;
33+ break ;
34+ } else if value == "--help" {
35+ break ;
36+ } else {
37+ }
38+ }
39+ v
40+ } ) ;
41+
2542#[ derive( Clone , Debug , Parser , PartialEq , Eq ) ]
2643#[ command(
2744 about = tr!( ABOUT ) ,
@@ -33,7 +50,7 @@ pub const NO_BOTS_DEFAULT_REGEX_PATTERN: &str = r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]";
3350 \n {}{}:{} {{usage}}
3451 \n {{all-args}}{{after-help}}\
3552 ",
36- Styles :: default ( ) . get_usage( ) . render( ) ,
53+ Styles :: default ( ) . get_usage( ) . render( ) ,
3754 tr!( usage:: HEADER ) ,
3855 Styles :: default ( ) . get_usage( ) . render_reset( )
3956 ) ,
@@ -43,25 +60,25 @@ pub const NO_BOTS_DEFAULT_REGEX_PATTERN: &str = r"(?:-|\s)[Bb]ot$|\[[Bb]ot\]";
4360pub struct CliOptions {
4461 #[ arg(
4562 default_value = "." ,
46- hide_default_value = true ,
63+ hide_default_value = true ,
4764 value_hint = ValueHint :: DirPath ,
4865 help = tr!( arguments:: INPUT ) ,
4966 value_name = tr!( value:: INPUT )
5067 ) ]
5168 pub input : PathBuf ,
5269 #[ arg(
53- action = clap:: ArgAction :: Help ,
70+ action = if * IS_SHORT { clap:: ArgAction :: HelpShort } else { clap :: ArgAction :: HelpLong } ,
5471 long,
55- short,
56- help = tr!( options:: HELP ) ,
72+ short,
73+ help = tr!( options:: HELP , short => & * IS_SHORT ) ,
5774 help_heading = tr!( options:: HEADER )
5875 ) ]
5976 pub help : Option < bool > ,
6077 #[ arg(
6178 action = clap:: ArgAction :: Version ,
62- long,
63- short = 'V' ,
64- help = tr!( options:: VERSION ) ,
79+ long,
80+ short = 'V' ,
81+ help = tr!( options:: VERSION ) ,
6582 help_heading = tr!( options:: HEADER )
6683 ) ]
6784 pub version : Option < bool > ,
@@ -96,13 +113,32 @@ pub struct InfoCliOptions {
96113 pub disabled_fields : Vec < InfoType > ,
97114 #[ arg( long, help = tr!( info:: NO_TITLE ) ) ]
98115 pub no_title : bool ,
99- #[ arg( long, default_value_t = 3usize , value_name = tr!( value:: NUM ) , help = tr!( info:: NUMBER_OF_AUTHORS ) ) ]
116+ #[ arg( long, default_value_t = 3usize , value_name = tr!( value:: NUM ) , hide_default_value = true ) ]
117+ #[ arg(
118+ help = tr!( info:: number_of_authors:: SHORT , def => 3 ) ,
119+ long_help = tr!( info:: number_of_authors:: LONG , def => 3 ) ,
120+ hide_default_value = true
121+ ) ]
100122 pub number_of_authors : usize ,
101- #[ arg( long, default_value_t = 6usize , value_name = tr!( value:: NUM ) , help = tr!( info:: NUMBER_OF_LANGUAGES ) ) ]
123+ #[ arg( long, default_value_t = 6usize , value_name = tr!( value:: NUM ) ) ]
124+ #[ arg(
125+ help = tr!( info:: number_of_languages:: SHORT , def => 6 ) ,
126+ long_help = tr!( info:: number_of_languages:: LONG , def => 6 ) ,
127+ hide_default_value = true
128+ ) ]
102129 pub number_of_languages : usize ,
103- #[ arg( long, default_value_t = 3usize , value_name = tr!( value:: NUM ) , help = tr!( info:: NUMBER_OF_FILE_CHURNS ) ) ]
130+ #[ arg( long, default_value_t = 3usize , value_name = tr!( value:: NUM ) ) ]
131+ #[ arg(
132+ help = tr!( info:: number_of_file_churns:: SHORT , def => 3 ) ,
133+ long_help = tr!( info:: number_of_file_churns:: LONG , def => 3 ) ,
134+ hide_default_value = true
135+ ) ]
104136 pub number_of_file_churns : usize ,
105- #[ arg( long, value_name = tr!( value:: NUM ) , help = tr!( info:: CHURN_POOL_SIZE ) ) ]
137+ #[ arg( long, value_name = tr!( value:: NUM ) ) ]
138+ #[ arg(
139+ help = tr!( info:: churn_pool_size:: SHORT ) ,
140+ long_help = tr!( info:: churn_pool_size:: LONG )
141+ ) ]
106142 pub churn_pool_size : Option < usize > ,
107143 #[ arg( long, short, num_args = 1 .., help = tr!( info:: EXCLUDE ) , value_name = tr!( value:: EXCLUDE ) ) ]
108144 pub exclude : Vec < String > ,
@@ -132,7 +168,12 @@ pub struct InfoCliOptions {
132168 default_values = & [ "programming" , "markup" ] ,
133169 short = 'T' ,
134170 value_enum,
135- help = tr!( info:: TYPE )
171+ ) ]
172+ #[ arg(
173+ help = tr!( info:: tipe:: SHORT , def => "programming, markup" , pos => "programming, markup, prose, data" ) ,
174+ long_help = tr!( info:: tipe:: LONG , def => "programming, markup" , pos => "programming, markup, prose, data" ) ,
175+ hide_default_value = true ,
176+ hide_possible_values = true ,
136177 ) ]
137178 pub r#type : Vec < LanguageType > ,
138179}
@@ -165,7 +206,7 @@ pub struct AsciiCliOptions {
165206}
166207
167208#[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
168- #[ command( next_help_heading = image:: HEADING ) ]
209+ #[ command( next_help_heading = tr! ( image:: HEADING ) ) ]
169210pub struct ImageCliOptions {
170211 #[ arg( long, short, value_name = tr!( value:: IMAGE ) , value_hint = ValueHint :: FilePath , help = tr!( image:: IMAGE ) ) ]
171212 pub image : Option < PathBuf > ,
@@ -177,7 +218,7 @@ pub struct ImageCliOptions {
177218 requires = "image" ,
178219 default_value_t = 16usize ,
179220 value_parser = PossibleValuesParser :: new( COLOR_RESOLUTIONS )
180- . map( |s| s. parse:: <usize >( ) . unwrap( ) ) ,
221+ . map( |s| s. parse:: <usize >( ) . unwrap( ) ) ,
181222 help = tr!( image:: COLOR_RESOLUTION )
182223 ) ]
183224 pub color_resolution : usize ,
@@ -186,7 +227,6 @@ pub struct ImageCliOptions {
186227#[ derive( Clone , Debug , Args , PartialEq , Eq ) ]
187228#[ command( next_help_heading = tr!( text:: HEADING ) ) ]
188229pub struct TextForamttingCliOptions {
189-
190230 #[ arg(
191231 long,
192232 short,
0 commit comments