mirror of
https://github.com/containers/podman.git
synced 2025-06-03 12:17:13 +08:00
Make podman generate systemd --new flag parsing more robust
First, use the pflag library to parse the flags. With this we can handle all corner cases such as -td or --detach=false. Second, preserve the root args with --new. They are used for all podman commands in the unit file. (e.g. podman --root /tmp run alpine) Signed-off-by: Paul Holzinger <paul.holzinger@web.de>
This commit is contained in:
@ -71,3 +71,30 @@ func quoteArguments(command []string) []string {
|
||||
}
|
||||
return command
|
||||
}
|
||||
|
||||
func removeDetachArg(args []string, argCount int) []string {
|
||||
// "--detach=false" could also be in the container entrypoint
|
||||
// split them off so we do not remove it there
|
||||
realArgs := args[len(args)-argCount:]
|
||||
flagArgs := removeArg("-d=false", args[:len(args)-argCount])
|
||||
flagArgs = removeArg("--detach=false", flagArgs)
|
||||
return append(flagArgs, realArgs...)
|
||||
}
|
||||
|
||||
func removeReplaceArg(args []string, argCount int) []string {
|
||||
// "--replace=false" could also be in the container entrypoint
|
||||
// split them off so we do not remove it there
|
||||
realArgs := args[len(args)-argCount:]
|
||||
flagArgs := removeArg("--replace=false", args[:len(args)-argCount])
|
||||
return append(flagArgs, realArgs...)
|
||||
}
|
||||
|
||||
func removeArg(arg string, args []string) []string {
|
||||
newArgs := []string{}
|
||||
for _, a := range args {
|
||||
if a != arg {
|
||||
newArgs = append(newArgs, a)
|
||||
}
|
||||
}
|
||||
return newArgs
|
||||
}
|
||||
|
Reference in New Issue
Block a user