@@ -13,8 +13,43 @@ pub struct InstallCmd {
1313 pub server : Option < ServerOpt > ,
1414}
1515
16+ #[ derive( Clone , Copy ) ]
1617pub enum ClientOpt {
1718 VsCode ,
19+ VsCodeInsiders ,
20+ VsCodium ,
21+ VsCodeOss ,
22+ Any ,
23+ }
24+
25+ impl ClientOpt {
26+ pub const fn as_cmds ( & self ) -> & ' static [ & ' static str ] {
27+ match self {
28+ ClientOpt :: VsCode => & [ "code" ] ,
29+ ClientOpt :: VsCodeInsiders => & [ "code-insiders" ] ,
30+ ClientOpt :: VsCodium => & [ "codium" ] ,
31+ ClientOpt :: VsCodeOss => & [ "code-oss" ] ,
32+ ClientOpt :: Any => & [ "code" , "code-insiders" , "codium" , "code-oss" ] ,
33+ }
34+ }
35+ }
36+
37+ impl Default for ClientOpt {
38+ fn default ( ) -> Self {
39+ ClientOpt :: Any
40+ }
41+ }
42+
43+ impl std:: str:: FromStr for ClientOpt {
44+ type Err = anyhow:: Error ;
45+
46+ fn from_str ( s : & str ) -> Result < Self , Self :: Err > {
47+ [ ClientOpt :: VsCode , ClientOpt :: VsCodeInsiders , ClientOpt :: VsCodium , ClientOpt :: VsCodeOss ]
48+ . iter ( )
49+ . copied ( )
50+ . find ( |c| [ s] == c. as_cmds ( ) )
51+ . ok_or_else ( || anyhow:: format_err!( "no such client" ) )
52+ }
1853}
1954
2055pub struct ServerOpt {
@@ -74,17 +109,13 @@ fn fix_path_for_mac() -> Result<()> {
74109 Ok ( ( ) )
75110}
76111
77- fn install_client ( ClientOpt :: VsCode : ClientOpt ) -> Result < ( ) > {
78- let _dir = pushd ( "./editors/code" ) ? ;
112+ fn install_client ( client_opt : ClientOpt ) -> Result < ( ) > {
113+ let _dir = pushd ( "./editors/code" ) ;
79114
80115 let find_code = |f : fn ( & str ) -> bool | -> Result < & ' static str > {
81- [ "code" , "code-insiders" , "codium" , "code-oss" ]
82- . iter ( )
83- . copied ( )
84- . find ( |bin| f ( bin) )
85- . ok_or_else ( || {
86- format_err ! ( "Can't execute `code --version`. Perhaps it is not in $PATH?" )
87- } )
116+ client_opt. as_cmds ( ) . iter ( ) . copied ( ) . find ( |bin| f ( bin) ) . ok_or_else ( || {
117+ format_err ! ( "Can't execute `code --version`. Perhaps it is not in $PATH?" )
118+ } )
88119 } ;
89120
90121 let installed_extensions = if cfg ! ( unix) {
0 commit comments