Skip to content

Commit

Permalink
Change way default parameters are handled.
Browse files Browse the repository at this point in the history
  • Loading branch information
mana-sys committed Jan 31, 2020
1 parent 8e7db87 commit de9aae8
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 29 deletions.
12 changes: 5 additions & 7 deletions internal/cli/command/deploy/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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
}
Expand Down Expand Up @@ -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 {
Expand Down
28 changes: 6 additions & 22 deletions internal/cli/command/package/cmd.go
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand All @@ -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")
Expand All @@ -46,31 +36,25 @@ 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
}

// 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
Expand Down

0 comments on commit de9aae8

Please sign in to comment.