From de9aae89ca4a48096e9bc46fae17f38f0a8d7114 Mon Sep 17 00:00:00 2001 From: mana-sys Date: Fri, 31 Jan 2020 10:33:38 -0800 Subject: [PATCH] Change way default parameters are handled. --- internal/cli/command/deploy/cmd.go | 12 +++++------- internal/cli/command/package/cmd.go | 28 ++++++---------------------- 2 files changed, 11 insertions(+), 29 deletions(-) diff --git a/internal/cli/command/deploy/cmd.go b/internal/cli/command/deploy/cmd.go index 06fccbc..e268dda 100644 --- a/internal/cli/command/deploy/cmd.go +++ b/internal/cli/command/deploy/cmd.go @@ -22,11 +22,6 @@ import ( "github.com/spf13/cobra" ) -type deployOpts struct { - templateFile string - stackName string -} - func NewDeployCommand(adhesiveCli *command.AdhesiveCli, opts *config.DeployOptions) *cobra.Command { cmd := &cobra.Command{ Use: "deploy", @@ -39,8 +34,7 @@ func NewDeployCommand(adhesiveCli *command.AdhesiveCli, opts *config.DeployOptio flags := cmd.Flags() flags.BoolVarP(&opts.Guided, "guided", "g", false, "Allow Adhesive to guide you through the deployment") flags.StringVar(&opts.StackName, "stack-name", "", "The name of the CloudFormation stack being deployed to") - flags.StringVar(&opts.TemplateFile, "template-file", "template.yml", - "The path to your CloudFormation template") + flags.StringVar(&opts.TemplateFile, "template-file", "", "The path to your CloudFormation template") return cmd } @@ -101,6 +95,10 @@ func deploy(adhesiveCli *command.AdhesiveCli) error { return errors.New("--stack-name must be specified") } + if opts.TemplateFile == "" { + opts.TemplateFile = "template.yml" + } + // Read the template file. b, err := ioutil.ReadFile(opts.TemplateFile) if err != nil { diff --git a/internal/cli/command/package/cmd.go b/internal/cli/command/package/cmd.go index e036640..063903b 100644 --- a/internal/cli/command/package/cmd.go +++ b/internal/cli/command/package/cmd.go @@ -12,16 +12,6 @@ import ( "github.com/spf13/cobra" ) -type packageOptions struct { - templateFile string - s3Bucket string - s3Prefix string - kmsKeyID string - outputTemplateFile string - useJSON bool - forceUpload bool -} - func NewPackageCommand(adhesiveCli *command.AdhesiveCli, opts *config.PackageOptions) *cobra.Command { cmd := &cobra.Command{ Use: "package", @@ -33,7 +23,7 @@ func NewPackageCommand(adhesiveCli *command.AdhesiveCli, opts *config.PackageOpt } flags := cmd.Flags() - flags.StringVar(&opts.TemplateFile, "template-file", "template.yml", "The path where your AWS CloudFormation template is located") + flags.StringVar(&opts.TemplateFile, "template-file", "", "The path where your AWS CloudFormation template is located") flags.StringVar(&opts.S3Bucket, "s3-bucket", "", "The S3 bucket where artifacts will be uploaded") flags.StringVar(&opts.S3Prefix, "s3-prefix", "", "The prefix added to the names of the artifacts uploaded to the S3 bucket") flags.StringVar(&opts.KmsKeyID, "kms-key-id", "", "The ID of the KMS key used to encrypt artifacts in the S3 bucket") @@ -46,10 +36,6 @@ func NewPackageCommand(adhesiveCli *command.AdhesiveCli, opts *config.PackageOpt func package1(adhesiveCli *command.AdhesiveCli) error { opts := adhesiveCli.Config.Package - var ( - s3Bucket string - s3Prefix string - ) if err := adhesiveCli.InitializeClients(); err != nil { return err @@ -57,20 +43,18 @@ func package1(adhesiveCli *command.AdhesiveCli) error { // Determine packaging parameters. These may come from either the packageOptions // or from the CLI instance itself. - if opts.S3Bucket != "" { - s3Bucket = opts.S3Bucket - } else { + if opts.S3Bucket == "" { return errors.New("must specify an S3 bucket") } - if opts.S3Prefix != "" { - s3Prefix = opts.S3Prefix + if opts.TemplateFile == "" { + opts.TemplateFile = "template.yml" } // Initialize a packager. pack := packager.NewFromS3(adhesiveCli.S3()) - pack.S3Bucket = s3Bucket - pack.S3Prefix = s3Prefix + pack.S3Bucket = opts.S3Bucket + pack.S3Prefix = opts.S3Prefix pack.KMSKeyID = opts.KmsKeyID if opts.UseJSON { pack.Format = packager.FormatJSON