From 565ec60b4c5b02e92731722062cf1c17929e97cd Mon Sep 17 00:00:00 2001 From: Alberto Faria Date: Tue, 16 Apr 2024 17:10:31 +0100 Subject: [PATCH] create: Allow empty strings anywhere in the container command Users should always be allowed to include an empty "" argument, regardless of whether the container image sets an entrypoint. Signed-off-by: Alberto Faria --- src/commands/create/custom_opts.rs | 13 +++++++++---- 1 file changed, 9 insertions(+), 4 deletions(-) diff --git a/src/commands/create/custom_opts.rs b/src/commands/create/custom_opts.rs index 46e1296..34b94f7 100644 --- a/src/commands/create/custom_opts.rs +++ b/src/commands/create/custom_opts.rs @@ -74,17 +74,22 @@ impl CustomOptions { .args() .iter() .flatten() + .filter(|a| !a.trim().is_empty()) .collect(); if let Some(&first_arg) = args.first() { - if first_arg.trim().is_empty() || first_arg == "no-entrypoint" { + if first_arg == "no-entrypoint" { args.remove(0); } } - // TODO: We currently assume that no entrypoint is given (either by being set by in the - // container image or through --entrypoint). Must somehow find whether the first arg is the - // entrypoint and ignore it in that case. + if let Some(&first_arg) = args.first() { + ensure!( + first_arg.starts_with("-"), + "unexpected entrypoint '{first_arg}' found; use an image without an entrypoint or with entrypoint \"no-entrypoint\", and/or pass in an empty \"\" entrypoint on the command line" + ); + } + let mut options = CustomOptions::parse_from( iter::once(&"podman run [] ".to_string()).chain(args), );