mirror of https://github.com/docker/compose.git
Switch automatically to interactive mode if one of the required flag is not set
Signed-off-by: Guillaume Lours <guillaume.lours@docker.com> Signed-off-by: Nicolas De Loof <nicolas.deloof@gmail.com>
This commit is contained in:
parent
51e04a4702
commit
0864513bfe
|
@ -42,7 +42,6 @@ func (s setupOptions) unsetRequiredArgs() []string {
|
|||
|
||||
func SetupCommand() *cobra.Command {
|
||||
var opts setupOptions
|
||||
var interactive bool
|
||||
|
||||
cmd := &cobra.Command{
|
||||
Use: "setup",
|
||||
|
@ -53,16 +52,10 @@ func SetupCommand() *cobra.Command {
|
|||
return plugin.PersistentPreRunE(cmd, args)
|
||||
},
|
||||
RunE: func(cmd *cobra.Command, args []string) error {
|
||||
if interactive {
|
||||
if requiredFlag := opts.unsetRequiredArgs(); len(requiredFlag) > 0 {
|
||||
if err := interactiveCli(&opts); err != nil {
|
||||
return err
|
||||
}
|
||||
} else {
|
||||
if requiredFlag := opts.unsetRequiredArgs(); len(requiredFlag) > 0 {
|
||||
fmt.Printf("required flag(s) %q not set", requiredFlag)
|
||||
cmd.Help()
|
||||
os.Exit(1)
|
||||
}
|
||||
}
|
||||
if opts.accessKeyID != "" && opts.secretAccessKey != "" {
|
||||
if err := saveCredentials(opts.context.Profile, opts.accessKeyID, opts.secretAccessKey); err != nil {
|
||||
|
@ -78,7 +71,6 @@ func SetupCommand() *cobra.Command {
|
|||
cmd.Flags().StringVarP(&opts.context.Region, "region", "r", "", "AWS region")
|
||||
cmd.Flags().StringVarP(&opts.accessKeyID, "aws-key-id", "k", "", "AWS Access Key ID")
|
||||
cmd.Flags().StringVarP(&opts.secretAccessKey, "aws-secret-key", "s", "", "AWS Secret Access Key")
|
||||
cmd.Flags().BoolVarP(&interactive, "interactive", "", false, "Interactively setup Context and Credentials")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
|
|
@ -9,17 +9,6 @@ import (
|
|||
"gotest.tools/v3/icmd"
|
||||
)
|
||||
|
||||
func TestSetupMandatoryArguments(t *testing.T) {
|
||||
cmd, cleanup := dockerCli.createTestCmd()
|
||||
defer cleanup()
|
||||
|
||||
cmd.Command = dockerCli.Command("ecs", "setup")
|
||||
usage := icmd.RunCmd(cmd).Assert(t, icmd.Expected{
|
||||
ExitCode: 1,
|
||||
}).Combined()
|
||||
goldenFile := "setup-required-flags.golden"
|
||||
golden.Assert(t, usage, goldenFile)
|
||||
}
|
||||
func TestDefaultAwsContextName(t *testing.T) {
|
||||
cmd, cleanup := dockerCli.createTestCmd()
|
||||
defer cleanup()
|
||||
|
|
|
@ -1,13 +0,0 @@
|
|||
required flag(s) ["profile" "cluster" "region"] not set
|
||||
Usage: docker ecs setup
|
||||
|
||||
|
||||
|
||||
Options:
|
||||
-k, --aws-key-id string AWS Access Key ID
|
||||
-s, --aws-secret-key string AWS Secret Access Key
|
||||
-c, --cluster string ECS cluster
|
||||
--interactive Interactively setup Context and Credentials
|
||||
-n, --name string Context Name (default "aws")
|
||||
-p, --profile string AWS Profile
|
||||
-r, --region string AWS region
|
Loading…
Reference in New Issue