-
Notifications
You must be signed in to change notification settings - Fork 268
Add azd config options command for config discoverability
#6390
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?
Changes from all commits
ca584ee
672a794
f4aaa3a
734ae36
f20cebb
6accc32
cf82fd0
2baf73e
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
|
|
||
| List all available configuration settings. | ||
|
|
||
| Usage | ||
| azd config options [flags] | ||
|
|
||
| Global Flags | ||
| -C, --cwd string : Sets the current working directory. | ||
| --debug : Enables debugging and diagnostics logging. | ||
| --docs : Opens the documentation for azd config options in your web browser. | ||
| -h, --help : Gets help for options. | ||
| --no-prompt : Accepts the default value instead of prompting, or it fails if there is no default. | ||
|
|
||
| Examples | ||
| List all available configuration settings in JSON format | ||
| azd config options -o json | ||
|
|
||
| List all available configuration settings in table format | ||
| azd config options | ||
|
|
||
| View a setting and set it | ||
| azd config options | ||
| azd config set <key> <value> | ||
|
|
||
|
|
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,38 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "log" | ||
|
|
||
| "github.com/azure/azure-dev/cli/azd/resources" | ||
| "github.com/braydonk/yaml" | ||
| ) | ||
|
|
||
| // EnvOnlyPrefix is the prefix used to mark environment-only configuration options | ||
| const EnvOnlyPrefix = "(env) " | ||
|
|
||
| // ConfigOption defines a configuration setting that can be set in azd config | ||
| type ConfigOption struct { | ||
| Key string `yaml:"key"` | ||
| Description string `yaml:"description"` | ||
| Type string `yaml:"type"` | ||
| AllowedValues []string `yaml:"allowedValues,omitempty"` | ||
| Example string `yaml:"example,omitempty"` | ||
| EnvVar string `yaml:"envVar,omitempty"` | ||
| } | ||
|
|
||
| var allConfigOptions []ConfigOption | ||
|
|
||
| func init() { | ||
| err := yaml.Unmarshal(resources.ConfigOptions, &allConfigOptions) | ||
| if err != nil { | ||
| log.Panicf("Can't unmarshal config options! %v", err) | ||
| } | ||
| } | ||
|
|
||
| // GetAllConfigOptions returns all available configuration options | ||
| func GetAllConfigOptions() []ConfigOption { | ||
| return allConfigOptions | ||
| } |
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,69 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| package config | ||
|
|
||
| import ( | ||
| "testing" | ||
|
|
||
| "github.com/stretchr/testify/require" | ||
| ) | ||
|
|
||
| func TestGetAllConfigOptions(t *testing.T) { | ||
| options := GetAllConfigOptions() | ||
|
|
||
| // Should have at least some options | ||
| require.NotEmpty(t, options) | ||
| require.Greater(t, len(options), 0) | ||
|
|
||
| // Check that we have the expected default options | ||
| foundDefaultsSubscription := false | ||
| foundDefaultsLocation := false | ||
| foundAlphaAll := false | ||
|
|
||
| for _, option := range options { | ||
| require.NotEmpty(t, option.Key, "Config option key should not be empty") | ||
| require.NotEmpty(t, option.Description, "Config option description should not be empty") | ||
| require.NotEmpty(t, option.Type, "Config option type should not be empty") | ||
|
|
||
| switch option.Key { | ||
| case "defaults.subscription": | ||
| foundDefaultsSubscription = true | ||
| require.Equal(t, "string", option.Type) | ||
| require.Contains(t, option.Description, "subscription") | ||
| case "defaults.location": | ||
| foundDefaultsLocation = true | ||
| require.Equal(t, "string", option.Type) | ||
| require.Contains(t, option.Description, "location") | ||
| case "alpha.all": | ||
| foundAlphaAll = true | ||
| require.Equal(t, "string", option.Type) | ||
| require.Contains(t, option.AllowedValues, "on") | ||
| require.Contains(t, option.AllowedValues, "off") | ||
| require.Equal(t, "AZD_ALPHA_ENABLE_ALL", option.EnvVar) | ||
| } | ||
| } | ||
|
|
||
| // Verify expected options are present | ||
| require.True(t, foundDefaultsSubscription, "defaults.subscription option should be present") | ||
| require.True(t, foundDefaultsLocation, "defaults.location option should be present") | ||
| require.True(t, foundAlphaAll, "alpha.all option should be present") | ||
| } | ||
|
|
||
| func TestConfigOptionStructure(t *testing.T) { | ||
| options := GetAllConfigOptions() | ||
|
|
||
| for _, option := range options { | ||
| // All options should have required fields | ||
| require.NotEmpty(t, option.Key) | ||
| require.NotEmpty(t, option.Description) | ||
| require.NotEmpty(t, option.Type) | ||
|
|
||
| // If AllowedValues is set, it should not be empty | ||
| if len(option.AllowedValues) > 0 { | ||
| for _, val := range option.AllowedValues { | ||
| require.NotEmpty(t, val, "Allowed value should not be empty") | ||
| } | ||
| } | ||
| } | ||
| } | ||
|
Comment on lines
+1
to
+69
|
||
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.
Real hard to read when wrapped:
Uh oh!
There was an error while loading. Please reload this page.
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.
I was about to leave the same comment. If all of these columns are important, I would recommend making the display a JSON format by default, rather than a table.
If we want a table, I think the columns should just be "Variable", "Current Value", "Allowed Values". Add a link to the docs for the description and examples, or add a tag
--verbosefor full content.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.
JSON is not very readable, linking to docs is meh experience. User could just expand their window :-)
Uh oh!
There was an error while loading. Please reload this page.
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.
The GUIDs in the Current Value and Example columns (
defaults.subscriptionkey) are making those columns extra wide and hard to read when wrapped. On my typical VS Code setup (left sidebar, window fully maximized), the output still wraps:I feel that Current Value would make most sense to omit, since users can use
azd config get? We don't include the current value inazd config options --output jsoneither. Otherwise, JSON feels more readable to me.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.
The way we format
azd config list-alphafeels more readable to me as well: