Skip to content

Commit

Permalink
Merge pull request #89 from ananthb/pod-name
Browse files Browse the repository at this point in the history
fix: support `podman pod create --name` option
  • Loading branch information
k9withabone authored Sep 24, 2024
2 parents 70c87c4 + cc00d45 commit 5356c2f
Showing 1 changed file with 37 additions and 6 deletions.
43 changes: 37 additions & 6 deletions src/cli/pod.rs
Original file line number Diff line number Diff line change
Expand Up @@ -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")
}
}

Expand Down Expand Up @@ -68,6 +79,22 @@ pub struct Create {
#[arg(long, visible_alias = "net", value_name = "MODE")]
network: Vec<String>,

/// 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<String>,

/// 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,
Expand Down Expand Up @@ -105,26 +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.
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<String>,
}

impl From<Create> 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();

Self {
network,
podman_args: (!podman_args.is_empty()).then_some(podman_args),
pod_name: None,
pod_name,
publish_port,
volume,
}
Expand Down

0 comments on commit 5356c2f

Please sign in to comment.