summaryrefslogtreecommitdiffhomepage
diff options
context:
space:
mode:
authorDavid Lönnhager <david.l@mullvad.net>2026-03-30 14:45:58 +0200
committerDavid Lönnhager <david.l@mullvad.net>2026-03-30 14:48:00 +0200
commite51dee1000745918fe86350d18b8064fe02dd6de (patch)
tree5b9697fe49b1b79a7daf6404c86675e8d69b1633
parenta1b3334347d31223f0f3560affb509423b9d4936 (diff)
downloadmullvadvpn-cleanup/DES-1044.tar.xz
mullvadvpn-cleanup/DES-1044.zip
List possible values for IP version in CLI helpcleanup/DES-1044
I.e. when running 'mullvad relay set ip-version <invalid>' or 'mullvad relay set ip-version -h'
-rw-r--r--Cargo.lock1
-rw-r--r--mullvad-cli/Cargo.toml2
-rw-r--r--mullvad-types/src/constraints/constraint.rs10
-rw-r--r--talpid-types/Cargo.toml1
-rw-r--r--talpid-types/src/net/mod.rs12
5 files changed, 25 insertions, 1 deletions
diff --git a/Cargo.lock b/Cargo.lock
index c20a3d5465..bb1a76126a 100644
--- a/Cargo.lock
+++ b/Cargo.lock
@@ -5485,6 +5485,7 @@ name = "talpid-types"
version = "0.0.0"
dependencies = [
"base64",
+ "clap",
"insta",
"ipnetwork",
"jnix",
diff --git a/mullvad-cli/Cargo.toml b/mullvad-cli/Cargo.toml
index 7c2e8f3c93..8a8702eb06 100644
--- a/mullvad-cli/Cargo.toml
+++ b/mullvad-cli/Cargo.toml
@@ -29,7 +29,7 @@ mullvad-version = { path = "../mullvad-version" }
natord = "1.0.9"
serde = { workspace = true }
serde_json = { workspace = true }
-talpid-types = { path = "../talpid-types" }
+talpid-types = { path = "../talpid-types", features = ["clap"] }
thiserror = { workspace = true }
tokio = { workspace = true, features = ["fs", "macros", "rt-multi-thread"] }
diff --git a/mullvad-types/src/constraints/constraint.rs b/mullvad-types/src/constraints/constraint.rs
index 870ea32254..a728340a33 100644
--- a/mullvad-types/src/constraints/constraint.rs
+++ b/mullvad-types/src/constraints/constraint.rs
@@ -212,4 +212,14 @@ where
}
self.0.parse_ref(cmd, arg, value).map(Constraint::Only)
}
+
+ fn possible_values(
+ &self,
+ ) -> Option<Box<dyn Iterator<Item = clap::builder::PossibleValue> + '_>> {
+ let any_value = std::iter::once(clap::builder::PossibleValue::new("any"));
+ Some(match self.0.possible_values() {
+ Some(inner) => Box::new(any_value.chain(inner)),
+ None => Box::new(any_value),
+ })
+ }
}
diff --git a/talpid-types/Cargo.toml b/talpid-types/Cargo.toml
index 4a73a93555..f7d1933ec4 100644
--- a/talpid-types/Cargo.toml
+++ b/talpid-types/Cargo.toml
@@ -8,6 +8,7 @@ license.workspace = true
[dependencies]
base64 = "0.22.0"
+clap = { workspace = true, optional = true }
ipnetwork = { workspace = true, features = ["serde"] }
log = { workspace = true }
serde = { workspace = true, features = ["derive"] }
diff --git a/talpid-types/src/net/mod.rs b/talpid-types/src/net/mod.rs
index a8bde40db6..a0461f04b4 100644
--- a/talpid-types/src/net/mod.rs
+++ b/talpid-types/src/net/mod.rs
@@ -354,9 +354,12 @@ impl fmt::Display for AllowedTunnelTraffic {
/// IP protocol version.
#[derive(Debug, Default, Copy, Clone, Eq, PartialEq, Deserialize, Serialize)]
#[serde(rename_all = "snake_case")]
+#[cfg_attr(feature = "clap", derive(clap::ValueEnum))]
pub enum IpVersion {
#[default]
+ #[cfg_attr(feature = "clap", value(name = "ipv4", alias = "v4"))]
V4,
+ #[cfg_attr(feature = "clap", value(name = "ipv6", alias = "v6"))]
V6,
}
@@ -390,6 +393,15 @@ impl FromStr for IpVersion {
}
}
+#[cfg(feature = "clap")]
+impl clap::builder::ValueParserFactory for IpVersion {
+ type Parser = clap::builder::EnumValueParser<IpVersion>;
+
+ fn value_parser() -> Self::Parser {
+ clap::builder::EnumValueParser::new()
+ }
+}
+
/// Returned when `IpVersion::from_str` fails to convert a string into a
/// [`IpVersion`] object.
#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]