exec: Support command arguments

This enables support for exec command argument starting with a '-'.
This uses the usual argument separator '--', for example:
  runc exec containerid -- ps -afx

Without this, cli interprets command argument and fails with
'flag provided but not defined'.

Signed-off-by: Tristan Cacqueray <tdecacqu@redhat.com>
This commit is contained in:
Tristan Cacqueray 2016-06-11 17:46:47 -04:00
parent b4ffe2974d
commit c562e4cd91
2 changed files with 5 additions and 2 deletions

View File

@ -17,7 +17,7 @@ import (
var execCommand = cli.Command{
Name: "exec",
Usage: "execute new process inside the container",
ArgsUsage: `<container-id> <container command>
ArgsUsage: `<container-id> -- <container command> [command options]
Where "<container-id>" is the name for the instance of the container and
"<container command>" is the command to be executed in the container.
@ -149,6 +149,9 @@ func getProcess(context *cli.Context, bundle string) (*specs.Process, error) {
}
p := spec.Process
p.Args = context.Args()[1:]
if len(p.Args) > 1 && p.Args[0] == "--" {
p.Args = p.Args[1:]
}
// override the cwd, if passed
if context.String("cwd") != "" {
p.Cwd = context.String("cwd")

View File

@ -2,7 +2,7 @@
runc exec - execute new process inside the container
# SYNOPSIS
runc exec [command options] <container-id> <container command>
runc exec [command options] <container-id> -- <container command> [args...]
Where "<container-id>" is the name for the instance of the container and
"<container command>" is the command to be executed in the container.