1+ mod completion;
12mod create;
23mod delete;
34mod inspect;
45mod list;
56mod token;
67
7- use crate :: Cli ;
8- use clap:: CommandFactory ;
9- use clap_complete:: {
10- generate,
11- shells:: { Bash , Fish , Zsh } ,
12- } ;
13- use std:: path:: Path ;
148use std:: process:: ExitCode ;
15- use std:: { env, io} ;
169
1710#[ derive( Debug , clap:: Subcommand ) ]
1811pub enum Command {
@@ -21,7 +14,7 @@ pub enum Command {
2114 Token ( token:: GetToken ) ,
2215 List ( list:: List ) ,
2316 Inspect ( inspect:: Inspect ) ,
24- Completion { shell : String } ,
17+ Completion ( completion :: GetCompletion ) ,
2518}
2619
2720impl Command {
@@ -32,25 +25,7 @@ impl Command {
3225 Self :: Token ( cmd) => cmd. run ( ) . await ,
3326 Self :: List ( cmd) => cmd. run ( ) . await ,
3427 Self :: Inspect ( cmd) => cmd. run ( ) . await ,
35- Self :: Completion { shell } => {
36- let mut cmd = Cli :: command ( ) ;
37- let bin_name = env:: args ( )
38- . next ( )
39- . and_then ( |path| {
40- Path :: new ( & path)
41- . file_stem ( )
42- . map ( |name| name. to_string_lossy ( ) . into_owned ( ) )
43- } )
44- . unwrap ( ) ;
45-
46- match shell. as_str ( ) {
47- "bash" => generate ( Bash , & mut cmd, & bin_name, & mut io:: stdout ( ) ) ,
48- "zsh" => generate ( Zsh , & mut cmd, & bin_name, & mut io:: stdout ( ) ) ,
49- "fish" => generate ( Fish , & mut cmd, & bin_name, & mut io:: stdout ( ) ) ,
50- _ => eprintln ! ( "Unsupported shell: {}" , shell) ,
51- }
52- Ok ( ( ) )
53- }
28+ Self :: Completion ( cmd) => cmd. run ( ) . await ,
5429 }
5530 . map ( |( ) | ExitCode :: SUCCESS )
5631 }
0 commit comments