Skip to content

Commit

Permalink
Config param override (#66)
Browse files Browse the repository at this point in the history
* add --config-param to override or set config manifest param entries

* removed unecessary if

---------

Co-authored-by: Marcio Goda <[email protected]>
  • Loading branch information
marciogoda and Marcio Goda authored Jan 28, 2025
1 parent 0164e7a commit 5281ced
Show file tree
Hide file tree
Showing 2 changed files with 27 additions and 5 deletions.
29 changes: 25 additions & 4 deletions command/command.go
Original file line number Diff line number Diff line change
Expand Up @@ -27,6 +27,7 @@ type GlobalArgs struct {
Command string
Component string
Commit string
ConfigParams []string
NoPullConfig bool
NoPullRelease bool
NoPullTerraform bool
Expand Down Expand Up @@ -103,12 +104,28 @@ func GetGlobalState(globalArgs *GlobalArgs, repoShouldExist bool) (*GlobalState,
state.Commit = globalArgs.Commit
}

err = overrideConfigManifestParams(&state)
if err != nil {
return nil, err
}

state.MonitoringClient = monitoring.NewDatadogClient()
}

return &state, nil
}

func overrideConfigManifestParams(state *GlobalState) error {
for _, param := range state.GlobalArgs.ConfigParams {
parts := strings.SplitN(param, "=", 2)
if len(parts) != 2 {
return errors.New("config param must be of the form key=value")
}
state.Manifest.Config.Params[parts[0]] = parts[1]
}
return nil
}

func handleArg(arg string, globalArgs *GlobalArgs, take func() (string, error)) (bool, error) {
if strings.HasPrefix(arg, "-") {
if handleSimpleFlag(arg, globalArgs) {
Expand Down Expand Up @@ -138,7 +155,13 @@ func handleSimpleFlag(arg string, globalArgs *GlobalArgs) bool {
}

func handleFlag(arg string, globalArgs *GlobalArgs, take func() (string, error)) (bool, error) {
if arg == "-c" || arg == "--component" {
if arg == "--config-param" {
value, err := take()
if err != nil {
return false, err
}
globalArgs.ConfigParams = append(globalArgs.ConfigParams, value)
} else if arg == "-c" || arg == "--component" {
value, err := take()
if err != nil {
return false, err
Expand Down Expand Up @@ -203,9 +226,7 @@ func GetComponentFromGit() (string, error) {
}
parts := strings.Split(strings.TrimSpace(string(output)), "/")
name := parts[len(parts)-1]
if strings.HasSuffix(name, ".git") {
name = name[:len(name)-4]
}
name = strings.TrimSuffix(name, ".git")
return name, nil
}

Expand Down
3 changes: 2 additions & 1 deletion main.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ const globalOptions = `Global options:
--component COMPONENT_NAME - override component name (inferred from git by default).
--commit GIT_COMMIT - override the git commit (inferred from git by default).
--config-param "key=value" - override or set a configuration parameter.
--no-pull-config - don't pull the config container (must exist).
--no-pull-release - don't pull the release container (must exist).
--no-pull-terraform - don't pull the terraform container (must exist).
Expand Down Expand Up @@ -173,7 +174,7 @@ Error in global options:
For usage run:
cdflow --help
cdflow2 --help
`

Expand Down

0 comments on commit 5281ced

Please sign in to comment.