add support for config set --if-not-set#1873
Conversation
📝 WalkthroughWalkthroughAdds an Changes
Sequence Diagram(s)sequenceDiagram
participant CLI as CLI (command/config.go)
participant ConfigSet as ConfigSet (pkg/cli/configSet.go)
participant CM as ConfigManager (ListConfig / PutConfig)
CLI->>ConfigSet: Call ConfigSet(name, value, ConfigSetOptions{IfNotSet})
alt IfNotSet == true
ConfigSet->>CM: ListConfig(project, filter=name)
CM-->>ConfigSet: returns existing configs
alt config exists
ConfigSet-->>CLI: return (false, nil) -- skip, no PutConfig
else config missing
ConfigSet->>CM: PutConfig(name, value)
CM-->>ConfigSet: success
ConfigSet-->>CLI: return (true, nil)
end
else IfNotSet == false
ConfigSet->>CM: PutConfig(name, value)
CM-->>ConfigSet: success or error
ConfigSet-->>CLI: return (true, nil) or (false, err)
end
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes Possibly related PRs
Suggested reviewers
Poem
🚥 Pre-merge checks | ✅ 2 | ❌ 1❌ Failed checks (1 warning)
✅ Passed checks (2 passed)
✏️ Tip: You can configure your own custom pre-merge checks in the settings. ✨ Finishing touches
Warning There were issues while running some tools. Please review the errors and either fix the tool's configuration or disable the tool if it's a critical failure. 🔧 golangci-lint (2.5.0)level=warning msg="[linters_context] running gomodguard failed: unable to read module file go.mod: current working directory must have a go.mod file: if you are not using go modules it is suggested to disable this linter" Comment |
Co-authored-by: Lio李歐 <lionello@users.noreply.github.com>
There was a problem hiding this comment.
Actionable comments posted: 0
Caution
Some comments are outside the diff and can’t be posted inline due to platform limitations.
⚠️ Outside diff range comments (1)
src/cmd/cli/command/config.go (1)
169-186: Success count does not account for skipped configs.When
--if-not-setis used, configs that already exist are skipped (not errors), but the countlen(envMap)-len(errs)still includes them. This results in misleading output like "Successfully set 3 config value(s)" when only 1 was actually set.Proposed fix: track actual set count
var errs []error + var setCount int for name, value := range envMap { didSet, err := cli.ConfigSet(cmd.Context(), projectName, session.Provider, name, value, cli.ConfigSetOptions{ IfNotSet: ifNotSet, }) if err != nil { errs = append(errs, err) } else if ifNotSet && !didSet { term.Info("Config", name, "is already set; skipping due to --if-not-set flag") } else { + setCount++ term.Info("Updated value for", name) } } - term.Infof("Successfully set %d config value(s)", len(envMap)-len(errs)) + term.Infof("Successfully set %d config value(s)", setCount)
Description
In order to support initial config values for 1-click deploy, this PR adds support for
config set --if-not-set. See DefangLabs/defang-github-action#38Linked Issues
Checklist
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.