@@ -281,7 +281,7 @@ enum RustupSubcmd {
281281 /// Generate tab-completion scripts for your shell
282282 #[ command( after_help = completions_help( ) , arg_required_else_help = true ) ]
283283 Completions {
284- shell : Shell ,
284+ shell : CompletionShell ,
285285
286286 #[ arg( default_value = "rustup" ) ]
287287 command : CompletionCommand ,
@@ -1853,8 +1853,57 @@ impl fmt::Display for CompletionCommand {
18531853 }
18541854}
18551855
1856+ #[ derive( clap:: ValueEnum , Clone , Copy , Debug ) ]
1857+ enum CompletionShell {
1858+ Bash ,
1859+ Elvish ,
1860+ Fish ,
1861+ Nushell ,
1862+ PowerShell ,
1863+ Zsh ,
1864+ }
1865+
1866+ impl fmt:: Display for CompletionShell {
1867+ fn fmt ( & self , f : & mut fmt:: Formatter < ' _ > ) -> fmt:: Result {
1868+ f. write_str ( match self {
1869+ CompletionShell :: Bash => "bash" ,
1870+ CompletionShell :: Elvish => "elvish" ,
1871+ CompletionShell :: Fish => "fish" ,
1872+ CompletionShell :: Nushell => "nushell" ,
1873+ CompletionShell :: PowerShell => "powershell" ,
1874+ CompletionShell :: Zsh => "zsh" ,
1875+ } )
1876+ }
1877+ }
1878+
1879+ impl clap_complete:: Generator for CompletionShell {
1880+ fn file_name ( & self , name : & str ) -> String {
1881+ match self {
1882+ CompletionShell :: Bash => Shell :: Bash . file_name ( name) ,
1883+ CompletionShell :: Elvish => Shell :: Elvish . file_name ( name) ,
1884+ CompletionShell :: Fish => Shell :: Fish . file_name ( name) ,
1885+ CompletionShell :: PowerShell => Shell :: PowerShell . file_name ( name) ,
1886+ CompletionShell :: Zsh => Shell :: Zsh . file_name ( name) ,
1887+
1888+ CompletionShell :: Nushell => clap_complete_nushell:: Nushell . file_name ( name) ,
1889+ }
1890+ }
1891+
1892+ fn generate ( & self , cmd : & clap:: Command , buf : & mut dyn Write ) {
1893+ match self {
1894+ CompletionShell :: Bash => Shell :: Bash . generate ( cmd, buf) ,
1895+ CompletionShell :: Elvish => Shell :: Elvish . generate ( cmd, buf) ,
1896+ CompletionShell :: Fish => Shell :: Fish . generate ( cmd, buf) ,
1897+ CompletionShell :: PowerShell => Shell :: PowerShell . generate ( cmd, buf) ,
1898+ CompletionShell :: Zsh => Shell :: Zsh . generate ( cmd, buf) ,
1899+
1900+ CompletionShell :: Nushell => clap_complete_nushell:: Nushell . generate ( cmd, buf) ,
1901+ }
1902+ }
1903+ }
1904+
18561905fn output_completion_script (
1857- shell : Shell ,
1906+ shell : CompletionShell ,
18581907 command : CompletionCommand ,
18591908 process : & Process ,
18601909) -> Result < ExitCode > {
@@ -1869,8 +1918,8 @@ fn output_completion_script(
18691918 }
18701919 CompletionCommand :: Cargo => {
18711920 let script = match shell {
1872- Shell :: Bash => "/etc/bash_completion.d/cargo" ,
1873- Shell :: Zsh => {
1921+ CompletionShell :: Bash => "/etc/bash_completion.d/cargo" ,
1922+ CompletionShell :: Zsh => {
18741923 writeln ! ( process. stdout( ) . lock( ) , "#compdef cargo" ) ?;
18751924 "/share/zsh/site-functions/_cargo"
18761925 }
0 commit comments