11use crate :: mod_file:: PlatformName ;
2+ use clap:: { Command , ValueEnum } ;
3+ use clap_complete:: Generator ;
24
35/// Command-line interface for Geode
46#[ derive( clap:: Parser , Debug ) ]
@@ -8,6 +10,40 @@ pub struct Args {
810 pub command : GeodeCommands ,
911}
1012
13+ #[ derive( Debug , ValueEnum , Clone ) ]
14+ pub enum Shell {
15+ Bash ,
16+ Elvish ,
17+ Fish ,
18+ PowerShell ,
19+ Zsh ,
20+ Nushell ,
21+ }
22+
23+ impl Generator for Shell {
24+ fn file_name ( & self , name : & str ) -> String {
25+ match self {
26+ Shell :: Bash => format ! ( "{}.bash" , name) ,
27+ Shell :: Elvish => format ! ( "{}.elv" , name) ,
28+ Shell :: Fish => format ! ( "{}.fish" , name) ,
29+ Shell :: PowerShell => format ! ( "_{}.ps1" , name) ,
30+ Shell :: Zsh => format ! ( "_{}" , name) ,
31+ Shell :: Nushell => clap_complete_nushell:: Nushell . file_name ( name) ,
32+ }
33+ }
34+
35+ fn generate ( & self , cmd : & Command , buf : & mut dyn std:: io:: Write ) {
36+ match self {
37+ Shell :: Bash => clap_complete:: shells:: Bash . generate ( cmd, buf) ,
38+ Shell :: Elvish => clap_complete:: shells:: Elvish . generate ( cmd, buf) ,
39+ Shell :: Fish => clap_complete:: shells:: Fish . generate ( cmd, buf) ,
40+ Shell :: PowerShell => clap_complete:: shells:: PowerShell . generate ( cmd, buf) ,
41+ Shell :: Zsh => clap_complete:: shells:: Zsh . generate ( cmd, buf) ,
42+ Shell :: Nushell => clap_complete_nushell:: Nushell . generate ( cmd, buf) ,
43+ }
44+ }
45+ }
46+
1147#[ derive( clap:: Subcommand , Debug ) ]
1248pub enum GeodeCommands {
1349 /// Initialize a new Geode project
@@ -17,7 +53,7 @@ pub enum GeodeCommands {
1753 } ,
1854
1955 /// Generate shell completions and print it to stdout
20- Completions { shell : clap_complete :: Shell } ,
56+ Completions { shell : Shell } ,
2157
2258 /// Generate manpage and print it to stdout
2359 GenerateManpage { } ,
0 commit comments