@@ -31,6 +31,8 @@ use utils::create_clash_service;
31
31
use utils:: delete_file;
32
32
use utils:: download_file;
33
33
use utils:: extract_gzip;
34
+ use utils:: proxy_export_cmd;
35
+ use utils:: proxy_unset_cmd;
34
36
35
37
#[ tokio:: main]
36
38
async fn main ( ) {
@@ -177,15 +179,14 @@ async fn main() {
177
179
}
178
180
Some ( Commands :: Proxy { proxy } ) => match proxy {
179
181
Some ( ProxyCommands :: Export ) => {
180
- let proxy_cmd = format ! (
181
- "export https_proxy=http://{hostname}:{http_port} \
182
- http_proxy=http://{hostname}:{http_port} \
183
- all_proxy=socks5://{hostname}:{socks_port}",
184
- hostname = "127.0.0.1" ,
185
- http_port = config. clash_config. port,
186
- socks_port = config. clash_config. socks_port
187
- ) ;
188
- println ! ( "{} Run ->\n {}" , prefix. blue( ) , & proxy_cmd. bold( ) ) ;
182
+ println ! (
183
+ "{}" ,
184
+ proxy_export_cmd(
185
+ "127.0.0.1" ,
186
+ & config. clash_config. port,
187
+ & config. clash_config. socks_port
188
+ )
189
+ )
189
190
}
190
191
Some ( ProxyCommands :: ExportLan ) => {
191
192
if !config. clash_config . allow_lan . unwrap_or ( false ) {
@@ -197,20 +198,22 @@ async fn main() {
197
198
return ;
198
199
}
199
200
200
- let host = local_ip ( ) . unwrap ( ) ;
201
- let proxy_cmd = format ! (
202
- "export https_proxy=http://{hostname}:{http_port} \
203
- http_proxy=http://{hostname}:{http_port} \
204
- all_proxy=socks5://{hostname}:{socks_port}",
205
- hostname = host,
206
- http_port = config. clash_config. port,
207
- socks_port = config. clash_config. socks_port
208
- ) ;
209
- println ! ( "{} Run ->\n {}" , prefix. blue( ) , & proxy_cmd. bold( ) ) ;
201
+ let hostname = local_ip ( ) ;
202
+ if let Ok ( hostname) = hostname {
203
+ println ! (
204
+ "{}" ,
205
+ proxy_export_cmd(
206
+ & hostname. to_string( ) ,
207
+ & config. clash_config. port,
208
+ & config. clash_config. socks_port
209
+ )
210
+ )
211
+ } else {
212
+ println ! ( "{} Failed to get local IP address" , prefix. red( ) ) ;
213
+ }
210
214
}
211
215
Some ( ProxyCommands :: Unset ) => {
212
- let proxy_cmd = "unset https_proxy http_proxy all_proxy" ;
213
- println ! ( "{} Run ->\n {}" , prefix. blue( ) , & proxy_cmd. bold( ) ) ;
216
+ println ! ( "{}" , proxy_unset_cmd( ) )
214
217
}
215
218
_ => {
216
219
println ! ( "{} No proxy command, --help for ussage" , prefix. red( ) ) ;
0 commit comments