summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2023-04-04 14:00:52 +0200
committerDavid Lönnhager <david.l@mullvad.net>2023-05-03 10:21:35 +0200
commit6d4a449cb66755ad8d80f99ba4d8f870f2ae9f08 (patch)
tree63f38353eb48221af3f3e1d9068fcea0565a478d
parente13b475d7cec89b564bd5c896ac24f7ca2596caf (diff)
downloadmullvadvpn-6d4a449cb66755ad8d80f99ba4d8f870f2ae9f08.tar.xz
mullvadvpn-6d4a449cb66755ad8d80f99ba4d8f870f2ae9f08.zip
Update CLI for mullvad-setup
-rw-r--r--Cargo.lock2
-rw-r--r--mullvad-setup/Cargo.toml2
-rw-r--r--mullvad-setup/src/main.rs63
3 files changed, 32 insertions, 35 deletions
diff --git a/Cargo.lock b/Cargo.lock
index 2fa92e93d8..2da40ab86d 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -2040,7 +2040,7 @@ dependencies = [
name = "mullvad-setup"
version = "0.0.0"
dependencies = [
- "clap 3.2.23",
+ "clap 4.2.7",
"env_logger 0.10.0",
"err-derive",
"lazy_static",
diff --git a/mullvad-setup/Cargo.toml b/mullvad-setup/Cargo.toml
index 91880b6bfc..651dac4aaf 100644
--- a/mullvad-setup/Cargo.toml
+++ b/mullvad-setup/Cargo.toml
@@ -12,7 +12,7 @@ name = "mullvad-setup"
path = "src/main.rs"
[dependencies]
-clap = { version = "3.0", features = ["cargo"] }
+clap = { version = "4.2.7", features = ["cargo"] }
env_logger = "0.10.0"
err-derive = "0.3.1"
lazy_static = "1.1.0"
diff --git a/mullvad-setup/src/main.rs b/mullvad-setup/src/main.rs
index 7e6c90b927..8cf6ad3778 100644
--- a/mullvad-setup/src/main.rs
+++ b/mullvad-setup/src/main.rs
@@ -1,4 +1,4 @@
-use clap::{crate_authors, crate_description, crate_name, App};
+use clap::Parser;
use mullvad_api::{self, proxy::ApiConnectionMode};
use mullvad_management_interface::MullvadProxyClient;
use mullvad_types::version::ParsedAppVersion;
@@ -71,47 +71,44 @@ pub enum Error {
ParseVersionStringError,
}
+#[derive(Debug, Parser)]
+#[command(author, version = mullvad_version::VERSION, about, long_about = None)]
+#[command(propagate_version = true)]
+#[command(
+ arg_required_else_help = true,
+ disable_help_subcommand = true,
+ disable_version_flag = true
+)]
+enum Cli {
+ /// Move a running daemon into a blocking state and save its target state
+ PrepareRestart,
+ /// Remove any firewall rules introduced by the daemon
+ ResetFirewall,
+ /// Remove the current device from the active account
+ RemoveDevice,
+ /// Checks whether the given version is older than the current version
+ IsOlderVersion {
+ /// Version string to compare the current version
+ #[arg(required = true)]
+ old_version: String,
+ },
+}
+
#[tokio::main]
async fn main() {
env_logger::init();
- let subcommands = vec![
- App::new("prepare-restart")
- .about("Move a running daemon into a blocking state and save its target state"),
- App::new("reset-firewall").about("Remove any firewall rules introduced by the daemon"),
- App::new("remove-device").about("Remove the current device from the active account"),
- App::new("is-older-version")
- .about("Checks whether the given version is older than the current version")
- .arg(
- clap::Arg::new("OLDVERSION")
- .required(true)
- .help("Version string to compare the current version"),
- ),
- ];
-
- let app = clap::App::new(crate_name!())
- .version(mullvad_version::VERSION)
- .author(crate_authors!())
- .about(crate_description!())
- .setting(clap::AppSettings::SubcommandRequiredElseHelp)
- .global_setting(clap::AppSettings::DisableHelpSubcommand)
- .global_setting(clap::AppSettings::DisableVersionFlag)
- .subcommands(subcommands);
-
- let matches = app.get_matches();
- let result = match matches.subcommand() {
- Some(("prepare-restart", _)) => prepare_restart().await,
- Some(("reset-firewall", _)) => reset_firewall().await,
- Some(("remove-device", _)) => remove_device().await,
- Some(("is-older-version", sub_matches)) => {
- let old_version = sub_matches.value_of("OLDVERSION").unwrap();
- match is_older_version(old_version) {
+ let result = match Cli::parse() {
+ Cli::PrepareRestart => prepare_restart().await,
+ Cli::ResetFirewall => reset_firewall().await,
+ Cli::RemoveDevice => remove_device().await,
+ Cli::IsOlderVersion { old_version } => {
+ match is_older_version(&old_version) {
// Returning exit status
Ok(status) => process::exit(status as i32),
Err(error) => Err(error),
}
}
- _ => unreachable!("No command matched"),
};
if let Err(e) = result {