diff --git a/src/cli/pod.rs b/src/cli/pod.rs index 2b7345e..d316357 100644 --- a/src/cli/pod.rs +++ b/src/cli/pod.rs @@ -39,8 +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 + 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") } } @@ -68,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, @@ -105,18 +132,22 @@ pub struct Create { /// /// This will be used as the name of the generated file when used with /// the --file option without a filename. - name: String, + /// + /// 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: _, + // Only set `PodName=` Quadlet option when `--name` is used. + name_positional: _, }: Create, ) -> Self { let podman_args = podman_args.to_string(); @@ -124,7 +155,7 @@ impl From for quadlet::Pod { Self { network, podman_args: (!podman_args.is_empty()).then_some(podman_args), - pod_name: None, + pod_name, publish_port, volume, }