summaryrefslogtreecommitdiffhomepage
path: root/mullvad-cli/src/cmds
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-08-21 15:24:07 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-08-21 16:39:49 +0200
commit0d6e7c9115bd53677fdad8cd83dc76b8fc9fc87d (patch)
tree2769d892910cadb7be62ba3ae1b62298c25a0070 /mullvad-cli/src/cmds
parent58fc8498458003f50e34d4f19296a3d9e014d10d (diff)
downloadmullvadvpn-0d6e7c9115bd53677fdad8cd83dc76b8fc9fc87d.tar.xz
mullvadvpn-0d6e7c9115bd53677fdad8cd83dc76b8fc9fc87d.zip
Add macro for indenting options in the CLI
Diffstat (limited to 'mullvad-cli/src/cmds')
-rw-r--r--mullvad-cli/src/cmds/relay.rs46
-rw-r--r--mullvad-cli/src/cmds/tunnel.rs50
2 files changed, 39 insertions, 57 deletions
diff --git a/mullvad-cli/src/cmds/relay.rs b/mullvad-cli/src/cmds/relay.rs
index 92696591d4..290c2cacd0 100644
--- a/mullvad-cli/src/cmds/relay.rs
+++ b/mullvad-cli/src/cmds/relay.rs
@@ -21,6 +21,7 @@ use talpid_types::net::{
};
use super::{relay_constraints::LocationArgs, BooleanOption};
+use crate::print_option;
#[derive(Subcommand, Debug)]
pub enum Relay {
@@ -223,10 +224,8 @@ impl Relay {
RelaySettings::Normal(constraints) => {
println!("Generic constraints");
- println!(
- "{:<4}{:<24}{}",
- "",
- "Location:",
+ print_option!(
+ "Location",
constraints
.location
.as_ref()
@@ -236,53 +235,40 @@ impl Relay {
}),
);
- println!(
- "{:<4}{:<24}{}",
- "", "Tunnel protocol:", constraints.tunnel_protocol,
- );
+ print_option!("Tunnel protocol", constraints.tunnel_protocol,);
- println!("{:<4}{:<24}{}", "", "Provider(s):", constraints.providers,);
- println!("{:<4}{:<24}{}", "", "Ownership:", constraints.ownership,);
+ print_option!("Provider(s)", constraints.providers,);
+ print_option!("Ownership", constraints.ownership,);
println!("OpenVPN constraints");
match constraints.openvpn_constraints.port {
Constraint::Any => {
- println!("{:<4}{:<24}{}", "", "Port:", "any",);
- println!("{:<4}{:<24}{}", "", "Transport:", "any",);
+ print_option!("Port", "any",);
+ print_option!("Transport", "any",);
}
Constraint::Only(transport_port) => {
- println!("{:<4}{:<24}{}", "", "Port:", transport_port.port,);
- println!("{:<4}{:<24}{}", "", "Transport:", transport_port.protocol,);
+ print_option!("Port", transport_port.port,);
+ print_option!("Transport", transport_port.protocol,);
}
}
println!("WireGuard constraints");
- println!(
- "{:<4}{:<24}{}",
- "", "Port:", constraints.wireguard_constraints.port,
- );
+ print_option!("Port", constraints.wireguard_constraints.port,);
- println!(
- "{:<4}{:<24}{}",
- "", "IP protocol:", constraints.wireguard_constraints.ip_version,
- );
+ print_option!("IP protocol", constraints.wireguard_constraints.ip_version,);
- println!(
- "{:<4}{:<24}{}",
- "",
- "Multihop state:",
+ print_option!(
+ "Multihop state",
if constraints.wireguard_constraints.use_multihop {
"enabled"
} else {
"disabled"
},
);
- println!(
- "{:<4}{:<24}{}",
- "",
- "Multihop entry:",
+ print_option!(
+ "Multihop entry",
constraints
.wireguard_constraints
.entry_location
diff --git a/mullvad-cli/src/cmds/tunnel.rs b/mullvad-cli/src/cmds/tunnel.rs
index 120fad327d..92e1c89d5c 100644
--- a/mullvad-cli/src/cmds/tunnel.rs
+++ b/mullvad-cli/src/cmds/tunnel.rs
@@ -7,6 +7,7 @@ use mullvad_types::{
};
use super::BooleanOption;
+use crate::print_option;
#[derive(Subcommand, Debug)]
pub enum Tunnel {
@@ -70,10 +71,8 @@ impl Tunnel {
println!("OpenVPN options");
- println!(
- "{:<4}{:<24}{}",
- "",
- "mssfix:",
+ print_option!(
+ "mssfix",
tunnel_options
.openvpn
.mssfix
@@ -83,33 +82,27 @@ impl Tunnel {
println!("WireGuard options");
- println!(
- "{:<4}{:<24}{}",
- "",
- "MTU:",
+ print_option!(
+ "MTU",
tunnel_options
.wireguard
.mtu
.map(|val| val.to_string())
.unwrap_or("unset".to_string()),
);
- println!(
- "{:<4}{:<24}{}",
- "", "Quantum resistance:", tunnel_options.wireguard.quantum_resistant,
+ print_option!(
+ "Quantum resistance",
+ tunnel_options.wireguard.quantum_resistant,
);
let key = rpc.get_wireguard_key().await?;
- println!("{:<4}{:<24}{}", "", "Public key:", key.key,);
- println!(
- "{:<4}{:<24}{}",
- "",
- "",
- format_args!("Created {}", key.created.with_timezone(&chrono::Local)),
- );
- println!(
- "{:<4}{:<24}{}",
- "",
- "Rotation interval:",
+ print_option!("Public key", key.key,);
+ print_option!(format_args!(
+ "Created {}",
+ key.created.with_timezone(&chrono::Local)
+ ),);
+ print_option!(
+ "Rotation interval",
match tunnel_options.wireguard.rotation_interval {
Some(interval) => interval.to_string(),
None => "unset".to_string(),
@@ -118,11 +111,14 @@ impl Tunnel {
println!("Generic options");
- if tunnel_options.generic.enable_ipv6 {
- println!("{:<4}{:<24}on", "", "IPv6:");
- } else {
- println!("{:<4}{:<24}off", "", "IPv6:");
- }
+ print_option!(
+ "IPv6",
+ if tunnel_options.generic.enable_ipv6 {
+ "on"
+ } else {
+ "off"
+ }
+ );
Ok(())
}