Skip to content

Commit

Permalink
Merge pull request #125 from containers/podman-run-hostname-short
Browse files Browse the repository at this point in the history
fix(container): support short flag `-h` for `podman run --hostname`
  • Loading branch information
k9withabone authored Oct 22, 2024
2 parents 8ef9420 + 0b70d12 commit f313850
Show file tree
Hide file tree
Showing 3 changed files with 21 additions and 4 deletions.
14 changes: 13 additions & 1 deletion src/cli.rs
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ use std::{
path::{Path, PathBuf},
};

use clap::{builder::TypedValueParser, Parser, Subcommand};
use clap::{builder::TypedValueParser, ArgAction, Parser, Subcommand};
use color_eyre::{
eyre::{ensure, eyre, WrapErr},
Help,
Expand Down Expand Up @@ -399,6 +399,7 @@ enum PodmanCommands {
///
/// For details on options see:
/// https://docs.podman.io/en/stable/markdown/podman-systemd.unit.5.html
#[command(disable_help_flag = true)]
Run {
/// The \[Container\] section
#[command(flatten)]
Expand All @@ -407,6 +408,17 @@ enum PodmanCommands {
/// The \[Service\] section
#[command(flatten)]
service: Service,

/// Print help
// Changed from default to support `podman run -h`, i.e. `podman run --hostname`.
#[arg(
short = '?',
long,
action = ArgAction::Help,
help = "Print help (see more with '--help')",
long_help = "Print help (see a summary with '-?')"
)]
help: (),
},

/// Generate a Podman Quadlet `.pod` file
Expand Down
2 changes: 1 addition & 1 deletion src/cli/container/quadlet.rs
Original file line number Diff line number Diff line change
Expand Up @@ -230,7 +230,7 @@ pub struct QuadletOptions {
/// Set the host name that is available inside the container
///
/// Converts to "HostName=NAME"
#[arg(long, value_name = "NAME")]
#[arg(short, long, value_name = "NAME")]
hostname: Option<String>,

/// Specify a static IPv4 address for the container
Expand Down
9 changes: 7 additions & 2 deletions src/cli/generate.rs
Original file line number Diff line number Diff line change
Expand Up @@ -164,7 +164,7 @@ impl Generate {

/// [`Parser`] for container creation CLI options.
#[derive(Parser, Debug)]
#[command(no_binary_name = true)]
#[command(no_binary_name = true, disable_help_flag = true)]
struct ContainerParser {
/// Podman global options
#[command(flatten)]
Expand Down Expand Up @@ -284,7 +284,7 @@ impl ContainerInspect {

/// [`Parser`] for pod creation CLI options.
#[derive(Parser, Debug)]
#[command(no_binary_name = true)]
#[command(no_binary_name = true, disable_help_flag = true)]
struct PodParser {
/// Podman global options
#[command(flatten)]
Expand Down Expand Up @@ -874,4 +874,9 @@ mod tests {
fn verify_container_parser_cli() {
ContainerParser::command().debug_assert();
}

#[test]
fn verify_pod_parser_cli() {
PodParser::command().debug_assert();
}
}

0 comments on commit f313850

Please sign in to comment.