Skip to content

Commit f584b53

Browse files
authored
Merge ea04611 into 7359418
2 parents 7359418 + ea04611 commit f584b53

8 files changed

Lines changed: 339 additions & 125 deletions

File tree

Gopkg.toml

Lines changed: 0 additions & 78 deletions
This file was deleted.

cmd/drawbridge/drawbridge.go

Lines changed: 35 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@ import (
1212
"github.com/analogj/drawbridge/pkg/utils"
1313
"github.com/analogj/drawbridge/pkg/version"
1414
"github.com/fatih/color"
15-
"gopkg.in/urfave/cli.v2"
15+
"github.com/urfave/cli/v2"
1616
"log"
1717
"strings"
1818
)
@@ -390,14 +390,14 @@ OPTIONS:
390390
func createFlags(appConfig config.Interface) ([]cli.Flag, error) {
391391
flags := []cli.Flag{
392392
&cli.StringFlag{
393-
Name: "active_config_template",
394-
Usage: "Active config_template",
395-
Value: appConfig.GetString("options.active_config_template"),
393+
Name: "active_config_template",
394+
Usage: "Active config_template",
395+
DefaultText: appConfig.GetString("options.active_config_template"),
396396
},
397397
&cli.StringSliceFlag{
398-
Name: "active_custom_templates",
399-
Usage: "Activated custom_templates",
400-
Value: cli.NewStringSlice(appConfig.GetStringSlice("options.active_custom_templates")...),
398+
Name: "active_custom_templates",
399+
Usage: "Activated custom_templates",
400+
DefaultText: strings.Join(appConfig.GetStringSlice("options.active_custom_templates"), ", "),
401401
},
402402
&cli.BoolFlag{
403403
Name: "dryrun",
@@ -451,16 +451,36 @@ func createFlags(appConfig config.Interface) ([]cli.Flag, error) {
451451
return flags, nil
452452
}
453453

454-
func createFlagHandler(appConfig config.Interface, defaultValues map[string]interface{}, cliFlags []string, c *cli.Context) (map[string]interface{}, error) {
455-
456-
cliAnswers := defaultValues
454+
func createFlagHandler(appConfig config.Interface, answerValues map[string]interface{}, cliFlags []string, c *cli.Context) (map[string]interface{}, error) {
455+
//there's 4 special cases we need to handle for "defaultOptions":
456+
//case 1: no flag override and no answer option
457+
//case 2: flag override and no answer option
458+
//case 3: no flag override and answer option
459+
//case 4: flag override and answer option
460+
461+
// the override order is:
462+
// default value from config
463+
// answer value from config
464+
// flag override
465+
466+
//get default defaultOptions from the config
467+
defaultOptions := map[string]interface{}{}
468+
appConfig.UnmarshalKey("options", &defaultOptions)
469+
470+
cliAnswers := answerValues
471+
//find answer defaultOptions (and set them)
472+
for optionName, _ := range defaultOptions {
473+
//check if the key is set as an answer/default
474+
if answerOptionValue, ok := answerValues[optionName]; ok {
475+
//this answer is actuall for an option. lets set it.
476+
appConfig.Set(fmt.Sprintf("options.%v", optionName), answerOptionValue)
477+
}
478+
}
457479

458480
for _, flagName := range cliFlags {
459-
//handle options
460-
options := map[string]interface{}{}
461-
appConfig.UnmarshalKey("options", &options)
462-
if _, ok := options[flagName]; ok {
463-
//this flag is actually an option. Lets set it.
481+
482+
if _, ok := defaultOptions[flagName]; ok {
483+
//this flag is actually an "option". Lets set it.
464484
appConfig.Set(fmt.Sprintf("options.%v", flagName), c.String(flagName))
465485
continue
466486
}

go.mod

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,18 @@
1+
module github.com/analogj/drawbridge
2+
3+
go 1.13
4+
5+
require (
6+
github.com/Jeffail/gabs v1.4.0
7+
github.com/fatih/color v1.9.0
8+
github.com/inconshreveable/go-update v0.0.0-20160112193335-8152e7eb6ccf
9+
github.com/kvz/logstreamer v0.0.0-20150507115422-a635b98146f0
10+
github.com/mitchellh/go-homedir v1.1.0
11+
github.com/spf13/viper v1.6.2
12+
github.com/stretchr/testify v1.5.1
13+
github.com/urfave/cli/v2 v2.2.0
14+
github.com/xeipuuv/gojsonschema v1.2.0
15+
github.com/xlab/treeprint v1.0.0
16+
golang.org/x/crypto v0.0.0-20200323165209-0ec3e9974c59
17+
gopkg.in/yaml.v2 v2.2.8
18+
)

0 commit comments

Comments
 (0)