@@ -8,6 +8,7 @@ use std::{
88} ;
99
1010use clap:: { crate_authors, crate_description, Arg , Command } ;
11+ use clap_complete:: { generate, Shell } ;
1112use const_format:: formatcp;
1213use crossterm:: tty:: IsTty ;
1314use itertools:: Itertools ;
@@ -292,6 +293,13 @@ When multiple overrides are specified, the first matching override wins."))
292293 . validator ( |s| s. parse :: < usize > ( ) )
293294 . required ( false ) ,
294295 )
296+ . arg (
297+ Arg :: new ( "completion" ) . long ( "completion" )
298+ . takes_value ( true )
299+ . value_name ( "SHELL" )
300+ . value_parser ( clap:: value_parser!( Shell ) )
301+ . help ( "Generate completion for a given shell" )
302+ )
295303 . arg (
296304 Arg :: new ( "paths" )
297305 . value_name ( "PATHS" )
@@ -603,7 +611,11 @@ fn parse_overrides_or_die(raw_overrides: &[String]) -> Vec<(LanguageOverride, Ve
603611/// Parse CLI arguments passed to the binary.
604612pub ( crate ) fn parse_args ( ) -> Mode {
605613 let matches = app ( ) . get_matches ( ) ;
606-
614+ if let Some ( shell) = matches. get_one :: < Shell > ( "completion" ) {
615+ generate ( * shell, & mut app ( ) , "difft" , & mut std:: io:: stdout ( ) ) ;
616+ // TODO: What should the exit code be? Should it be defined in src/exit_codes.rs
617+ std:: process:: exit ( 0 ) ;
618+ }
607619 let color_output = match matches. value_of ( "color" ) . expect ( "color has a default" ) {
608620 "always" => ColorOutput :: Always ,
609621 "never" => ColorOutput :: Never ,
0 commit comments