Skip to content

Commit f909984

Browse files
committed
get formatting right
1 parent e85db53 commit f909984

File tree

2 files changed

+22
-12
lines changed

2 files changed

+22
-12
lines changed

cli/deployment/config.go

Lines changed: 15 additions & 11 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

scripts/cligen/main.go

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,6 +41,7 @@ type Data struct {
4141

4242
type Field struct {
4343
Key string
44+
Env string
4445
Usage string
4546
Flag string
4647
Shorthand string
@@ -129,6 +130,7 @@ func (g *Generator) generateAll() (*Data, error) {
129130
}
130131
f := Field{
131132
Key: key,
133+
Env: "CODER_" + strings.ReplaceAll(strings.ToUpper(key), "-", "_"),
132134
}
133135
ft, ok := field.Type.(*ast.Ident)
134136
if !ok {
@@ -216,6 +218,8 @@ func (c Data) Render() string {
216218
}
217219

218220
const deploymentConfigTemplate = `// Code generated by go generate; DO NOT EDIT.
221+
// This file was generated by the script at scripts/cligen
222+
// The data for populating this file is from the DeploymentConfig struct in codersdk.
219223
package deployment
220224
221225
import (
@@ -226,6 +230,7 @@ import (
226230
"github.com/spf13/viper"
227231
228232
"github.com/coder/coder/codersdk"
233+
"github.com/coder/coder/cli/cliui"
229234
)
230235
231236
func Config(vip *viper.Viper) (codersdk.DeploymentConfig, error) {
@@ -235,6 +240,7 @@ func Config(vip *viper.Viper) (codersdk.DeploymentConfig, error) {
235240
236241
func DefaultViper() *viper.Viper {
237242
v := viper.New()
243+
v.SetEnvPrefix("coder")
238244
v.AutomaticEnv()
239245
{{- range .Fields }}
240246
{{- if .Default }}
@@ -248,7 +254,7 @@ func DefaultViper() *viper.Viper {
248254
func AttachFlags(flagset *pflag.FlagSet, vip *viper.Viper) {
249255
{{- range .Fields }}
250256
{{- if and (.Flag) (not .Enterprise) }}
251-
_ = flagset.{{ .Type }}P("{{ .Flag }}", "{{ .Shorthand }}", vip.Get{{ .Type }}("{{ .Key }}"), ` + "`{{ .Usage }}`" + `)
257+
_ = flagset.{{ .Type }}P("{{ .Flag }}", "{{ .Shorthand }}", vip.Get{{ .Type }}("{{ .Key }}"), ` + "`{{ .Usage }}`" + `+"\n"+cliui.Styles.Placeholder.Render("Consumes ${{ .Env }}"))
252258
_ = vip.BindPFlag("{{ .Key }}", flagset.Lookup("{{ .Flag }}"))
253259
{{- if and .Hidden }}
254260
_ = flagset.MarkHidden("{{ .Flag }}")

0 commit comments

Comments
 (0)