From c806b4a1e8e96d756feaab9c2d6888d59165dc8a Mon Sep 17 00:00:00 2001 From: Ananth Bhaskararaman Date: Wed, 26 Jun 2024 02:04:19 +0530 Subject: [PATCH 1/3] fix: Read pod name from podman create args Signed-off-by: Ananth Bhaskararaman --- src/cli/pod.rs | 17 +++++++++++++++-- 1 file changed, 15 insertions(+), 2 deletions(-) diff --git a/src/cli/pod.rs b/src/cli/pod.rs index 2b7345e..04efb1a 100644 --- a/src/cli/pod.rs +++ b/src/cli/pod.rs @@ -105,6 +105,10 @@ pub struct Create { /// /// This will be used as the name of the generated file when used with /// the --file option without a filename. + #[arg(required_unless_present="name", value_name="NAME")] + name_pos: String, + + #[arg(required_unless_present="name_pos", long, value_name="NAME")] name: String, } @@ -116,15 +120,24 @@ impl From for quadlet::Pod { volume, podman_args, // Name used when creating the `quadlet::File`. - name: _, + name_pos, + name, }: Create, ) -> Self { let podman_args = podman_args.to_string(); + + let pod_name: Option; + if name_pos.is_empty() { + pod_name = Some(name); + } else { + pod_name = Some(name_pos); + } + Self { network, podman_args: (!podman_args.is_empty()).then_some(podman_args), - pod_name: None, + pod_name: pod_name, publish_port, volume, } From a3009d0ca704aa4c3fe541fcf71071bac4fedfc4 Mon Sep 17 00:00:00 2001 From: Ananth Bhaskararaman Date: Fri, 20 Sep 2024 22:54:54 +0530 Subject: [PATCH 2/3] fix: Require one of name or name_positional Signed-off-by: Ananth Bhaskararaman --- src/cli/pod.rs | 31 +++++++++++++++++-------------- 1 file changed, 17 insertions(+), 14 deletions(-) diff --git a/src/cli/pod.rs b/src/cli/pod.rs index 04efb1a..d168ad2 100644 --- a/src/cli/pod.rs +++ b/src/cli/pod.rs @@ -40,7 +40,11 @@ impl Pod { /// The name (without extension) of the generated Quadlet file. pub fn name(&self) -> &str { let Self::Create { create } = self; - &create.name + create + .name + .as_ref() + .or(create.name_positional.as_ref()) + .expect("`name` or `name_positional` is required") } } @@ -105,11 +109,14 @@ pub struct Create { /// /// This will be used as the name of the generated file when used with /// the --file option without a filename. - #[arg(required_unless_present="name", value_name="NAME")] - name_pos: String, + #[arg(required_unless_present = "name", value_name = "NAME")] + name_positional: Option, - #[arg(required_unless_present="name_pos", long, value_name="NAME")] - name: String, + /// The name of the pod to create. + /// + /// Must be specified if `name_positional` is not. + #[arg(conflicts_with = "name_positional", long, value_name = "NAME")] + name: Option, } impl From for quadlet::Pod { @@ -120,24 +127,20 @@ impl From for quadlet::Pod { volume, podman_args, // Name used when creating the `quadlet::File`. - name_pos, + name_positional, name, }: Create, ) -> Self { let podman_args = podman_args.to_string(); - - let pod_name: Option; - if name_pos.is_empty() { - pod_name = Some(name); - } else { - pod_name = Some(name_pos); - } + let pod_name = name_positional + .or(name) + .expect("`name` or `name_positional` is required"); Self { network, podman_args: (!podman_args.is_empty()).then_some(podman_args), - pod_name: pod_name, + pod_name: Some(pod_name), publish_port, volume, } From cc00d456890afaf15de801211985745fdfe55e21 Mon Sep 17 00:00:00 2001 From: Paul Nettleton Date: Mon, 23 Sep 2024 01:15:17 -0500 Subject: [PATCH 3/3] fix(pod): only set `PodName=` when `--name` is used Only set `PodName=` Quadlet option when `--name` is used per the discussion in #88. Renamed `name` to `name_flag`. Moved `name_flag` so that it matches the `PodName=` position on podman-systemd.unit(5) man page. Added more user-friendly documentation to `name_flag` help text. Set `long = "name"` and `short` arg attributes for `name_flag`. Refactored `Pod::name()` a bit to use more destructuring and `Option::as_deref()`. Signed-off-by: Paul Nettleton --- src/cli/pod.rs | 57 +++++++++++++++++++++++++++++++------------------- 1 file changed, 36 insertions(+), 21 deletions(-) diff --git a/src/cli/pod.rs b/src/cli/pod.rs index d168ad2..d316357 100644 --- a/src/cli/pod.rs +++ b/src/cli/pod.rs @@ -39,12 +39,19 @@ pub enum Pod { impl Pod { /// The name (without extension) of the generated Quadlet file. pub fn name(&self) -> &str { - let Self::Create { create } = self; - create - .name - .as_ref() - .or(create.name_positional.as_ref()) - .expect("`name` or `name_positional` is required") + let Self::Create { + create: + Create { + name_flag, + name_positional, + .. + }, + } = self; + + name_flag + .as_deref() + .or(name_positional.as_deref()) + .expect("`name_flag` or `name_positional` is required") } } @@ -72,6 +79,22 @@ pub struct Create { #[arg(long, visible_alias = "net", value_name = "MODE")] network: Vec, + /// The name of the pod to create. + /// + /// Converts to "PodName=NAME". + /// + /// This will be used as the name of the generated file when used with + /// the --file option without a filename. + /// + /// Either this option or the name positional argument must be given. + #[arg( + conflicts_with = "name_positional", + short, + long = "name", + value_name = "NAME" + )] + name_flag: Option, + /// Publish a container's port, or a range of ports, within this pod to the host. /// /// **Note:** You must not publish ports of containers in the pod individually, @@ -109,38 +132,30 @@ pub struct Create { /// /// This will be used as the name of the generated file when used with /// the --file option without a filename. - #[arg(required_unless_present = "name", value_name = "NAME")] - name_positional: Option, - - /// The name of the pod to create. /// - /// Must be specified if `name_positional` is not. - #[arg(conflicts_with = "name_positional", long, value_name = "NAME")] - name: Option, + /// Either this positional argument or the name option must be given. + #[arg(required_unless_present = "name_flag", value_name = "NAME")] + name_positional: Option, } impl From for quadlet::Pod { fn from( Create { network, + name_flag: pod_name, publish: publish_port, volume, podman_args, - // Name used when creating the `quadlet::File`. - name_positional, - name, + // Only set `PodName=` Quadlet option when `--name` is used. + name_positional: _, }: Create, ) -> Self { let podman_args = podman_args.to_string(); - let pod_name = name_positional - .or(name) - .expect("`name` or `name_positional` is required"); - Self { network, podman_args: (!podman_args.is_empty()).then_some(podman_args), - pod_name: Some(pod_name), + pod_name, publish_port, volume, }