Skip to content

Commit aa14432

Browse files
committed
Merge branch 'main' into augustoccesar/configure-rustls
2 parents 097fb40 + c5a3017 commit aa14432

File tree

2 files changed

+65
-30
lines changed

2 files changed

+65
-30
lines changed

linkup-cli/src/main.rs

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -182,10 +182,28 @@ enum Commands {
182182
Reset,
183183

184184
#[clap(about = "Route session traffic to a local service")]
185-
Local { service_names: Vec<String> },
185+
Local {
186+
service_names: Vec<String>,
187+
#[arg(
188+
short,
189+
long,
190+
help = "Route all the services to local. Cannot be used with SERVICE_NAMES.",
191+
conflicts_with = "service_names"
192+
)]
193+
all: bool,
194+
},
186195

187196
#[clap(about = "Route session traffic to a remote service")]
188-
Remote { service_names: Vec<String> },
197+
Remote {
198+
service_names: Vec<String>,
199+
#[arg(
200+
short,
201+
long,
202+
help = "Route all the services to remote. Cannot be used with SERVICE_NAMES.",
203+
conflicts_with = "service_names"
204+
)]
205+
all: bool,
206+
},
189207

190208
#[clap(about = "View linkup component and service status")]
191209
Status {
@@ -232,8 +250,8 @@ fn main() -> Result<()> {
232250
Commands::Start { no_tunnel } => start(&cli.config, *no_tunnel),
233251
Commands::Stop => stop(),
234252
Commands::Reset => reset(),
235-
Commands::Local { service_names } => local(service_names),
236-
Commands::Remote { service_names } => remote(service_names),
253+
Commands::Local { service_names, all } => local(service_names, *all),
254+
Commands::Remote { service_names, all } => remote(service_names, *all),
237255
Commands::Status { json, all } => status(*json, *all),
238256
Commands::LocalDNS { subcommand } => match subcommand {
239257
LocalDNSSubcommand::Install => local_dns::install(&cli.config),

linkup-cli/src/remote_local.rs

Lines changed: 43 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -6,59 +6,76 @@ use crate::{
66
CliError, LINKUP_LOCALSERVER_PORT,
77
};
88

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 {
1111
return Err(CliError::NoSuchService(
1212
"No service names provided".to_string(),
1313
));
1414
}
15+
1516
let mut state = LocalState::load()?;
1617

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+
}
2429
}
2530

2631
state.save()?;
2732
load_server_states(state)?;
2833

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+
}
3342

3443
Ok(())
3544
}
3645

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 {
3948
return Err(CliError::NoSuchService(
4049
"No service names provided".to_string(),
4150
));
4251
}
4352

4453
let mut state = LocalState::load()?;
4554

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+
}
5366
}
5467

5568
state.save()?;
5669
load_server_states(state)?;
5770

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+
}
6279

6380
Ok(())
6481
}

0 commit comments

Comments
 (0)