@@ -41,6 +41,7 @@ type Data struct {
41
41
42
42
type Field struct {
43
43
Key string
44
+ Env string
44
45
Usage string
45
46
Flag string
46
47
Shorthand string
@@ -129,6 +130,7 @@ func (g *Generator) generateAll() (*Data, error) {
129
130
}
130
131
f := Field {
131
132
Key : key ,
133
+ Env : "CODER_" + strings .ReplaceAll (strings .ToUpper (key ), "-" , "_" ),
132
134
}
133
135
ft , ok := field .Type .(* ast.Ident )
134
136
if ! ok {
@@ -216,6 +218,8 @@ func (c Data) Render() string {
216
218
}
217
219
218
220
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.
219
223
package deployment
220
224
221
225
import (
@@ -226,6 +230,7 @@ import (
226
230
"github.com/spf13/viper"
227
231
228
232
"github.com/coder/coder/codersdk"
233
+ "github.com/coder/coder/cli/cliui"
229
234
)
230
235
231
236
func Config(vip *viper.Viper) (codersdk.DeploymentConfig, error) {
@@ -235,6 +240,7 @@ func Config(vip *viper.Viper) (codersdk.DeploymentConfig, error) {
235
240
236
241
func DefaultViper() *viper.Viper {
237
242
v := viper.New()
243
+ v.SetEnvPrefix("coder")
238
244
v.AutomaticEnv()
239
245
{{- range .Fields }}
240
246
{{- if .Default }}
@@ -248,7 +254,7 @@ func DefaultViper() *viper.Viper {
248
254
func AttachFlags(flagset *pflag.FlagSet, vip *viper.Viper) {
249
255
{{- range .Fields }}
250
256
{{- 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 }}") )
252
258
_ = vip.BindPFlag("{{ .Key }}", flagset.Lookup("{{ .Flag }}"))
253
259
{{- if and .Hidden }}
254
260
_ = flagset.MarkHidden("{{ .Flag }}")
0 commit comments