Add --rm to run command (as not yet implemented)

Signed-off-by: Ulysses Souza <ulyssessouza@gmail.com>
This commit is contained in:
Ulysses Souza 2020-10-27 01:57:35 +01:00
parent 1ecfa703f5
commit 69083e07e6
2 changed files with 11 additions and 2 deletions

View File

@ -18,6 +18,7 @@ package run
import ( import (
"context" "context"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -43,7 +44,7 @@ func Command(contextType string) *cobra.Command {
if len(args) > 1 { if len(args) > 1 {
opts.Command = args[1:] opts.Command = args[1:]
} }
return runRun(cmd.Context(), args[0], opts) return runRun(cmd.Context(), args[0], contextType, opts)
}, },
} }
cmd.Flags().SetInterspersed(false) cmd.Flags().SetInterspersed(false)
@ -58,15 +59,22 @@ func Command(contextType string) *cobra.Command {
cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables") cmd.Flags().StringArrayVarP(&opts.Environment, "env", "e", []string{}, "Set environment variables")
cmd.Flags().StringArrayVar(&opts.EnvironmentFiles, "env-file", []string{}, "Path to environment files to be translated as environment variables") cmd.Flags().StringArrayVar(&opts.EnvironmentFiles, "env-file", []string{}, "Path to environment files to be translated as environment variables")
cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits") cmd.Flags().StringVarP(&opts.RestartPolicyCondition, "restart", "", containers.RestartPolicyNone, "Restart policy to apply when a container exits")
cmd.Flags().BoolVar(&opts.Rm, "rm", false, "Automatically remove the container when it exits")
if contextType == store.AciContextType { if contextType == store.AciContextType {
cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name") cmd.Flags().StringVar(&opts.DomainName, "domainname", "", "Container NIS domain name")
} }
_ = cmd.Flags().MarkHidden("rm")
return cmd return cmd
} }
func runRun(ctx context.Context, image string, opts run.Opts) error { func runRun(ctx context.Context, image string, contextType string, opts run.Opts) error {
if opts.Rm {
return errors.New(`Option "rm" is not yet implemented for context type: ` + contextType)
}
c, err := client.New(ctx) c, err := client.New(ctx)
if err != nil { if err != nil {
return err return err

View File

@ -46,6 +46,7 @@ type Opts struct {
EnvironmentFiles []string EnvironmentFiles []string
RestartPolicyCondition string RestartPolicyCondition string
DomainName string DomainName string
Rm bool
} }
// ToContainerConfig convert run options to a container configuration // ToContainerConfig convert run options to a container configuration