@@ -6,59 +6,76 @@ use crate::{
6
6
CliError , LINKUP_LOCALSERVER_PORT ,
7
7
} ;
8
8
9
- pub fn remote ( service_names : & [ String ] ) -> Result < ( ) , CliError > {
10
- if service_names. is_empty ( ) {
9
+ pub fn remote ( service_names : & [ String ] , all : bool ) -> Result < ( ) , CliError > {
10
+ if service_names. is_empty ( ) && !all {
11
11
return Err ( CliError :: NoSuchService (
12
12
"No service names provided" . to_string ( ) ,
13
13
) ) ;
14
14
}
15
+
15
16
let mut state = LocalState :: load ( ) ?;
16
17
17
- for service_name in service_names {
18
- let service = state
19
- . services
20
- . iter_mut ( )
21
- . find ( |s| s. name . as_str ( ) == service_name)
22
- . ok_or_else ( || CliError :: NoSuchService ( service_name. to_string ( ) ) ) ?;
23
- service. current = ServiceTarget :: Remote ;
18
+ for service in state. services . iter_mut ( ) {
19
+ if all {
20
+ service. current = ServiceTarget :: Remote ;
21
+ continue ;
22
+ }
23
+
24
+ if service_names. contains ( & service. name ) {
25
+ service. current = ServiceTarget :: Remote ;
26
+ } else {
27
+ return Err ( CliError :: NoSuchService ( service. name . clone ( ) ) ) ;
28
+ }
24
29
}
25
30
26
31
state. save ( ) ?;
27
32
load_server_states ( state) ?;
28
33
29
- println ! (
30
- "Linkup is routing {} traffic to the remote server" ,
31
- service_names. join( ", " )
32
- ) ;
34
+ if all {
35
+ println ! ( "Linkup is routing all traffic to the remote servers" ) ;
36
+ } else {
37
+ println ! (
38
+ "Linkup is routing {} traffic to the remote server" ,
39
+ service_names. join( ", " )
40
+ ) ;
41
+ }
33
42
34
43
Ok ( ( ) )
35
44
}
36
45
37
- pub fn local ( service_names : & [ String ] ) -> Result < ( ) , CliError > {
38
- if service_names. is_empty ( ) {
46
+ pub fn local ( service_names : & [ String ] , all : bool ) -> Result < ( ) , CliError > {
47
+ if service_names. is_empty ( ) && !all {
39
48
return Err ( CliError :: NoSuchService (
40
49
"No service names provided" . to_string ( ) ,
41
50
) ) ;
42
51
}
43
52
44
53
let mut state = LocalState :: load ( ) ?;
45
54
46
- for service_name in service_names {
47
- let service = state
48
- . services
49
- . iter_mut ( )
50
- . find ( |s| s. name . as_str ( ) == service_name)
51
- . ok_or_else ( || CliError :: NoSuchService ( service_name. to_string ( ) ) ) ?;
52
- service. current = ServiceTarget :: Local ;
55
+ for service in state. services . iter_mut ( ) {
56
+ if all {
57
+ service. current = ServiceTarget :: Local ;
58
+ continue ;
59
+ }
60
+
61
+ if service_names. contains ( & service. name ) {
62
+ service. current = ServiceTarget :: Local ;
63
+ } else {
64
+ return Err ( CliError :: NoSuchService ( service. name . clone ( ) ) ) ;
65
+ }
53
66
}
54
67
55
68
state. save ( ) ?;
56
69
load_server_states ( state) ?;
57
70
58
- println ! (
59
- "Linkup is routing {} traffic to the local server" ,
60
- service_names. join( ", " )
61
- ) ;
71
+ if all {
72
+ println ! ( "Linkup is routing all traffic to the local servers" ) ;
73
+ } else {
74
+ println ! (
75
+ "Linkup is routing {} traffic to the local server" ,
76
+ service_names. join( ", " )
77
+ ) ;
78
+ }
62
79
63
80
Ok ( ( ) )
64
81
}
0 commit comments