-
Notifications
You must be signed in to change notification settings - Fork 222
Add config management commands (show, edit, set) #3532
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Conversation
dgannon991
left a comment
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Additional tests AI recommend adding;
- Attempt to set a non-primitive field (slice/map/struct) and assert a descriptive error.
- Attempt to set an exported field whose underlying type is a named numeric/enum to ensure SetString/SetInt works for named types.
- Tests that simulate FileSystem failures for SaveConfig and CreateDefaultConfig.
- An integration-style test for porter.SetConfig path that exercises loading existing file + saving changes (you already have this partly, but exercise the CLI path end-to-end).
- Test case-insensitive inputs if you decide to normalize values (or add docs that values are exact).
| field := t.Field(i) | ||
|
|
||
| // Check toml, yaml, and json tags | ||
| for _, tagKey := range []string{"toml", "yaml", "json"} { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Does this mean if we miss an annotation in a config file, it won't work here? (E.G. I provide TOML + YAML, but the user requests JSON)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If for example we something like this, where the JSON annotation is missing:
type Data struct {
BuilDriver string `toml:"build-driver" yaml:"build-driver"
}This function will find anyway because it loops through all of them, the requested format is not considered here. It currently works because I assume that the value will be same across all formats.
The annotation is used during marshaling to the requested format, meaning it must there for each supported configuration format.
For this specific function it will only "fail" if the field annotation differs between formats, which is a little confusing.
All input is appreciated, I'm not 100% sure what I think myself.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ah OK, that makes a lot more sense. Is there any form of validation we could add for the values being the same across the different format types?
ef1143d to
d5e2332
Compare
Added tests for the first two points, they were already handled, but not explicitly tested. |
4de0b0e to
7fe69bb
Compare
Implement Phase 1: config writer foundation with persistence layer for saving Porter config files. New functionality: - GetConfigPath: locate existing config or default to config.toml - DetectConfigFormat: extract format from file extension - SaveConfig: marshal and write config to disk - CreateDefaultConfig: create new config with defaults Changes: - Add toml/yaml/json tags to config structs for proper marshaling - Support all formats: toml, yaml, yml, json - 17 comprehensive unit tests, all passing Related to getporter#1077 Signed-off-by: Kim Christensen <[email protected]>
Implement reflection-based config value setter with dot notation support and domain validation via struct tags. Features: - Dynamic field discovery using toml/yaml/json tags - Unlimited nesting depth (e.g., logs.level, telemetry.protocol) - Type conversion for string, bool, int, uint, float - Domain validation via validate:"oneof=..." tags - No external dependencies (custom tag parser) Files: - pkg/config/setter.go: SetConfigValue and ValidateConfigValue - pkg/config/setter_test.go: 33 tests covering mechanisms - pkg/config/datastore.go: Added validate tags to constrained fields - pkg/config/logs.go: Added validate tags to LogConfig/TelemetryConfig Validated fields include verbosity, runtime-driver, build-driver, schema-check, logs.level, telemetry.protocol/compression. All 56 config package tests pass. Signed-off-by: Kim Christensen <[email protected]>
Implement `porter config show` command to display current Porter configuration in multiple formats (toml, json, yaml). - Add ConfigShowOptions with format validation - Add ShowConfig() to read config from file or show defaults - Add CLI command with -o/--output flag - Add comprehensive unit tests (24 test cases) - Auto-generate command documentation Phase 3 of config commands implementation (getporter#1077) Signed-off-by: Kim Christensen <[email protected]>
Implement `porter config edit` command to edit Porter configuration in user's default editor. - Add ConfigEditOptions with validation - Add EditConfig() to open config in $EDITOR - Create default config if none exists - Validate syntax before saving changes - Preserve existing file format (toml/yaml/json) - Add unit tests for validation and default creation Phase 4 of config commands implementation (getporter#1077) Signed-off-by: Kim Christensen <[email protected]>
Signed-off-by: Kim Christensen <[email protected]>
Add porter config set KEY VALUE command to set individual config values programmatically. Command creates default config if none exists, preserves file format (toml/yaml/json), validates values, and supports nested fields via dot notation. Signed-off-by: Kim Christensen <[email protected]>
Add guard check in findFieldByTagWithMeta to validate input is a struct before calling NumField(). Prevents panic when function is called with non-struct types. Add comprehensive test coverage for string, int, bool, slice, and map types to verify guard behavior. Signed-off-by: Kim Christensen <[email protected]>
Add comprehensive test coverage for reviewer feedback: 1. Non-primitive field handling - validates descriptive errors when attempting to set slice/map fields 2. Named type support - verifies SetString/SetInt/SetBool work correctly with named types (e.g., type LogLevel string) Tests use mock struct with named int/bool types since actual config only has named string (LogLevel). Signed-off-by: Kim Christensen <[email protected]>
7fe69bb to
eb347eb
Compare
Accept case-insensitive input for oneof-validated fields (e.g., "DEBUG", "Docker", "Info") and normalize to correct casing from validation tags. Uses strings.EqualFold for comparison and integrates normalization into validation flow to avoid duplicate path traversal. Signed-off-by: Kim Christensen <[email protected]>
What does this change
Adds three new commands for managing Porter's configuration file:
porter config show [--output FORMAT]- Display current configporter config edit- Edit config in $EDITORporter config set KEY VALUE- Set individual config valuesExamples
Show config (displays defaults if no config exists):
Set individual values:
Edit in your preferred editor:
$ porter config edit # Opens config.toml in $EDITORFeatures
show -oconverts between formatsWhat issue does it fix
Closes #1077
Notes for the reviewer
Key design decisions:
validate:"oneof=..."struct tagsChecklist