@@ -71,7 +71,7 @@ fn split_time_range(tokens: &[String], clock: &dyn Clock) -> anyhow::Result<(Tim
7171}
7272
7373pub fn get_app ( ) -> App < ' static , ' static > {
74- App :: new ( "RTW" )
74+ App :: new ( crate_name ! ( ) )
7575 . version ( crate_version ! ( ) )
7676 . author ( "PicoJr" )
7777 . about ( "rust time tracking CLI" )
@@ -224,6 +224,16 @@ pub fn get_app() -> App<'static, 'static> {
224224 . arg ( Arg :: with_name ( "id" ) . required ( true ) . help ( "activity id" ) ) ,
225225 )
226226 . subcommand ( SubCommand :: with_name ( "cancel" ) . about ( "cancel current activity" ) )
227+ . subcommand (
228+ SubCommand :: with_name ( "completion" )
229+ . about ( "generate completion file" )
230+ . arg (
231+ Arg :: with_name ( "shell" )
232+ . possible_values ( & [ "bash" , "zsh" , "fish" , "powershell" , "elvish" ] )
233+ . takes_value ( true )
234+ . required ( true ) ,
235+ ) ,
236+ )
227237}
228238
229239pub fn parse_start_args ( start_m : & ArgMatches , clock : & dyn Clock ) -> anyhow:: Result < ( Time , Tags ) > {
@@ -327,6 +337,19 @@ pub fn parse_delete_args(delete_m: &ArgMatches) -> anyhow::Result<ActivityId> {
327337 }
328338}
329339
340+ pub fn parse_completion_args ( completion_m : & ArgMatches ) -> anyhow:: Result < clap:: Shell > {
341+ let shell_maybe = completion_m. value_of ( "shell" ) ;
342+ match shell_maybe {
343+ Some ( "bash" ) => Ok ( clap:: Shell :: Bash ) ,
344+ Some ( "zsh" ) => Ok ( clap:: Shell :: Zsh ) ,
345+ Some ( "fish" ) => Ok ( clap:: Shell :: Fish ) ,
346+ Some ( "powershell" ) => Ok ( clap:: Shell :: PowerShell ) ,
347+ Some ( "elvish" ) => Ok ( clap:: Shell :: Elvish ) ,
348+ None => Err ( anyhow:: anyhow!( "missing shell" ) ) , // should never happen thanks to clap check
349+ _ => Err ( anyhow:: anyhow!( "invalid shell" ) ) , // should never happen thanks to clap check
350+ }
351+ }
352+
330353#[ cfg( test) ]
331354mod tests {
332355 use crate :: chrono_clock:: ChronoClock ;
0 commit comments