File tree 2 files changed +28
-3
lines changed
2 files changed +28
-3
lines changed Original file line number Diff line number Diff line change @@ -3,8 +3,8 @@ use std::sync::{
3
3
Arc ,
4
4
} ;
5
5
6
- use anyhow:: Result ;
7
- use clap:: Parser ;
6
+ use anyhow:: { anyhow , Result } ;
7
+ use clap:: { CommandFactory , Parser } ;
8
8
use gitoxide:: shared:: pretty:: prepare_and_run;
9
9
use gitoxide_core as core;
10
10
@@ -169,6 +169,21 @@ pub fn main() -> Result<()> {
169
169
)
170
170
}
171
171
} ,
172
+ Subcommands :: Completions { shell, out_dir } => {
173
+ let mut app = Args :: command ( ) ;
174
+
175
+ let shell = shell
176
+ . or_else ( clap_complete:: Shell :: from_env)
177
+ . ok_or_else ( || anyhow ! ( "The shell could not be derived from the environment" ) ) ?;
178
+
179
+ let bin_name = app. get_name ( ) . to_owned ( ) ;
180
+ if let Some ( out_dir) = out_dir {
181
+ clap_complete:: generate_to ( shell, & mut app, bin_name, & out_dir) ?;
182
+ } else {
183
+ clap_complete:: generate ( shell, & mut app, bin_name, & mut std:: io:: stdout ( ) ) ;
184
+ }
185
+ Ok ( ( ) )
186
+ }
172
187
} ?;
173
188
Ok ( ( ) )
174
189
}
Original file line number Diff line number Diff line change
1
+ use clap_complete:: Shell ;
1
2
use std:: path:: PathBuf ;
2
3
3
4
#[ derive( Debug , clap:: Parser ) ]
4
- #[ clap( about = "The rusty git" , version = option_env!( "GIX_VERSION" ) ) ]
5
+ #[ clap( name = "ein" , about = "The rusty git" , version = option_env!( "GIX_VERSION" ) ) ]
5
6
#[ clap( subcommand_required = true ) ]
6
7
pub struct Args {
7
8
/// Do not display verbose messages and progress information
@@ -39,6 +40,15 @@ pub enum Subcommands {
39
40
/// A selection of useful tools
40
41
#[ clap( subcommand) ]
41
42
Tool ( ToolCommands ) ,
43
+ /// Generate shell completions to stdout or a directory.
44
+ #[ clap( visible_alias = "generate-completions" , visible_alias = "shell-completions" ) ]
45
+ Completions {
46
+ /// The shell to generate completions for. Otherwise it's derived from the environment.
47
+ #[ clap( long, short) ]
48
+ shell : Option < Shell > ,
49
+ /// The output directory in case multiple files are generated. If not provided, will write to stdout.
50
+ out_dir : Option < String > ,
51
+ } ,
42
52
#[ cfg( debug_assertions) ]
43
53
Panic ,
44
54
}
You can’t perform that action at this time.
0 commit comments