Skip to content

Commit 8fffb7e

Browse files
authored
change default deploytype to avoid defaulting to invalid type (#207)
1 parent 485072e commit 8fffb7e

File tree

5 files changed

+42
-25
lines changed

5 files changed

+42
-25
lines changed

cmd/create.go

Lines changed: 20 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,12 @@ import (
77
"os"
88
"strings"
99

10+
"golang.org/x/exp/maps"
11+
"gopkg.in/yaml.v3"
12+
1013
"github.com/manifoldco/promptui"
1114
log "github.com/sirupsen/logrus"
1215
"github.com/spf13/cobra"
13-
"golang.org/x/exp/maps"
14-
"gopkg.in/yaml.v3"
1516

1617
"github.com/Azure/draft/pkg/config"
1718
"github.com/Azure/draft/pkg/deployments"
@@ -33,6 +34,10 @@ var flagVariablesMap = make(map[string]string)
3334
const LANGUAGE_VARIABLE = "LANGUAGE"
3435
const TWO_SPACES = " "
3536

37+
// Flag defaults
38+
const emptyDefaultFlagValue = ""
39+
const currentDirDefaultFlagValue = "."
40+
3641
type createCmd struct {
3742
appName string
3843
lang string
@@ -70,11 +75,11 @@ func newCreateCmd() *cobra.Command {
7075

7176
f := cmd.Flags()
7277

73-
f.StringVarP(&cc.createConfigPath, "create-config", "c", "", "specify the path to the configuration file")
74-
f.StringVarP(&cc.appName, "app", "a", "", "specify the name of the helm release")
75-
f.StringVarP(&cc.lang, "language", "l", "", "specify the language used to create the Kubernetes deployment")
76-
f.StringVarP(&cc.dest, "destination", "d", ".", "specify the path to the project directory")
77-
f.StringVarP(&cc.deployType, "deploy-type", "", ".", "specify deployement type (eg. helm, kustomize, manifests)")
78+
f.StringVarP(&cc.createConfigPath, "create-config", "c", emptyDefaultFlagValue, "specify the path to the configuration file")
79+
f.StringVarP(&cc.appName, "app", "a", emptyDefaultFlagValue, "specify the name of the helm release")
80+
f.StringVarP(&cc.lang, "language", "l", emptyDefaultFlagValue, "specify the language used to create the Kubernetes deployment")
81+
f.StringVarP(&cc.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory")
82+
f.StringVarP(&cc.deployType, "deploy-type", "", emptyDefaultFlagValue, "specify deployement type (eg. helm, kustomize, manifests)")
7883
f.BoolVar(&cc.dockerfileOnly, "dockerfile-only", false, "only create Dockerfile in the project directory")
7984
f.BoolVar(&cc.deploymentOnly, "deployment-only", false, "only create deployment files in the project directory")
8085
f.BoolVar(&cc.skipFileDetection, "skip-file-detection", false, "skip file detection step")
@@ -287,7 +292,10 @@ func (cc *createCmd) createDeployment() error {
287292

288293
if cc.createConfig.DeployType != "" {
289294
deployType = strings.ToLower(cc.createConfig.DeployType)
290-
deployConfig := d.GetConfig(deployType)
295+
deployConfig, err := d.GetConfig(deployType)
296+
if err != nil {
297+
return err
298+
}
291299
if deployConfig == nil {
292300
return errors.New("invalid deployment type")
293301
}
@@ -311,7 +319,10 @@ func (cc *createCmd) createDeployment() error {
311319
deployType = cc.deployType
312320
}
313321

314-
deployConfig := d.GetConfig(deployType)
322+
deployConfig, err := d.GetConfig(deployType)
323+
if err != nil {
324+
return err
325+
}
315326
customInputs, err = prompts.RunPromptsFromConfigWithSkips(deployConfig, maps.Keys(flagVariablesMap))
316327
if err != nil {
317328
return err

cmd/create_test.go

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -207,6 +207,11 @@ func (mcc *createCmd) mockDetectLanguage() (*config.DraftConfig, string, error)
207207
return nil, "", ErrNoLanguageDetected
208208
}
209209

210+
func TestDefaultValues(t *testing.T) {
211+
assert.Equal(t, emptyDefaultFlagValue, "")
212+
assert.Equal(t, currentDirDefaultFlagValue, ".")
213+
}
214+
210215
func getAllDeploymentFiles(src string) (error, []string) {
211216
deploymentFiles := []string{}
212217
err := filepath.Walk(src,

cmd/generate-workflow.go

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -44,15 +44,15 @@ with draft on AKS. This command assumes the 'setup-gh' command has been run prop
4444
}
4545

4646
f := cmd.Flags()
47-
f.StringVarP(&gwCmd.workflowConfig.AksClusterName, "cluster-name", "c", "", "specify the AKS cluster name")
48-
f.StringVarP(&gwCmd.workflowConfig.AcrName, "registry-name", "r", "", "specify the Azure container registry name")
49-
f.StringVar(&gwCmd.workflowConfig.ContainerName, "container-name", "", "specify the container image name")
50-
f.StringVarP(&gwCmd.workflowConfig.ResourceGroupName, "resource-group", "g", "", "specify the Azure resource group of your AKS cluster")
51-
f.StringVarP(&gwCmd.dest, "destination", "d", ".", "specify the path to the project directory")
52-
f.StringVarP(&gwCmd.workflowConfig.BranchName, "branch", "b", "", "specify the Github branch to automatically deploy from")
53-
f.StringVar(&gwCmd.deployType, "deploy-type", "", "specify the type of deployment")
47+
f.StringVarP(&gwCmd.workflowConfig.AksClusterName, "cluster-name", "c", emptyDefaultFlagValue, "specify the AKS cluster name")
48+
f.StringVarP(&gwCmd.workflowConfig.AcrName, "registry-name", "r", emptyDefaultFlagValue, "specify the Azure container registry name")
49+
f.StringVar(&gwCmd.workflowConfig.ContainerName, "container-name", emptyDefaultFlagValue, "specify the container image name")
50+
f.StringVarP(&gwCmd.workflowConfig.ResourceGroupName, "resource-group", "g", emptyDefaultFlagValue, "specify the Azure resource group of your AKS cluster")
51+
f.StringVarP(&gwCmd.dest, "destination", "d", currentDirDefaultFlagValue, "specify the path to the project directory")
52+
f.StringVarP(&gwCmd.workflowConfig.BranchName, "branch", "b", emptyDefaultFlagValue, "specify the Github branch to automatically deploy from")
53+
f.StringVar(&gwCmd.deployType, "deploy-type", emptyDefaultFlagValue, "specify the type of deployment")
5454
f.StringArrayVarP(&gwCmd.flagVariables, "variable", "", []string{}, "pass additional variables")
55-
f.StringVarP(&gwCmd.workflowConfig.BuildContextPath, "build-context-path", "x", "", "specify the docker build context path")
55+
f.StringVarP(&gwCmd.workflowConfig.BuildContextPath, "build-context-path", "x", emptyDefaultFlagValue, "specify the docker build context path")
5656
gwCmd.templateWriter = &writers.LocalFSWriter{}
5757
return cmd
5858
}

cmd/setup-gh.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -41,10 +41,10 @@ application and service principle, and will configure that application to trust
4141
}
4242

4343
f := cmd.Flags()
44-
f.StringVarP(&sc.AppName, "app", "a", "", "specify the Azure Active Directory application name")
45-
f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", "", "specify the Azure subscription ID")
46-
f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", "", "specify the Azure resource group name")
47-
f.StringVarP(&sc.Repo, "gh-repo", "g", "", "specify the github repository link")
44+
f.StringVarP(&sc.AppName, "app", "a", emptyDefaultFlagValue, "specify the Azure Active Directory application name")
45+
f.StringVarP(&sc.SubscriptionID, "subscription-id", "s", emptyDefaultFlagValue, "specify the Azure subscription ID")
46+
f.StringVarP(&sc.ResourceGroupName, "resource-group", "r", emptyDefaultFlagValue, "specify the Azure resource group name")
47+
f.StringVarP(&sc.Repo, "gh-repo", "g", emptyDefaultFlagValue, "specify the github repository link")
4848
sc.Provider = provider
4949
return cmd
5050
}

pkg/deployments/deployments.go

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -6,10 +6,11 @@ import (
66
"io/fs"
77
"path"
88

9-
log "github.com/sirupsen/logrus"
109
"golang.org/x/exp/maps"
1110
"gopkg.in/yaml.v3"
1211

12+
log "github.com/sirupsen/logrus"
13+
1314
"github.com/Azure/draft/pkg/config"
1415
"github.com/Azure/draft/pkg/embedutils"
1516
"github.com/Azure/draft/pkg/osutil"
@@ -74,12 +75,12 @@ func (d *Deployments) loadConfig(lang string) (*config.DraftConfig, error) {
7475
return &draftConfig, nil
7576
}
7677

77-
func (d *Deployments) GetConfig(deployType string) *config.DraftConfig {
78+
func (d *Deployments) GetConfig(deployType string) (*config.DraftConfig, error) {
7879
val, ok := d.configs[deployType]
7980
if !ok {
80-
return nil
81+
return nil, fmt.Errorf("deployment type: %s is not currently supported", deployType)
8182
}
82-
return val
83+
return val, nil
8384
}
8485

8586
func (d *Deployments) PopulateConfigs() {

0 commit comments

Comments
 (0)