Refactor option definitions

This commit is contained in:
Denis Arh
2022-02-08 09:13:56 +01:00
parent 440354e431
commit d103d60a3d
37 changed files with 479 additions and 471 deletions
@@ -27,7 +27,7 @@ type (
func {{ .func }}() (o *{{ .struct }}) {
o = &{{ .struct }}{
{{- range .options }}
{{- if .default }}
{{- if or .default }}
{{ .expIdent }}: {{ .default }},
{{- end }}
{{- end }}
+17 -6
View File
@@ -29,14 +29,25 @@ options:
imports: [ for i in {for g in app.corteza.options for i in g.imports {"\(i)": i}} {i}]
groups: [
for g in app.corteza.options {
func: g.expIdent
struct: g.expIdent + "Opt"
options: g.options
}
for g in app.corteza.options {
func: g.expIdent
struct: g.expIdent + "Opt"
options: [
for o in g.options {
o
default?: string
if (o.defaultGoExpr != _|_) {
default: o.defaultGoExpr
}
if (o.defaultGoExpr == _|_ && o.defaultValue != _|_) {
default: "\"" + o.defaultValue + "\""
}
},
]
},
]
}
},
]
+16 -10
View File
@@ -4,30 +4,30 @@ import (
"strings"
)
#_ENV: =~ "^[A-Z][A-Z0-9_]*[A-Z0-9]?$"
#_ENV: =~"^[A-Z][A-Z0-9_]*[A-Z0-9]?$"
//#_optName: =~ "^[a-zA-Z][a-zA-Z0-9\\s]*[a-zA-Z0-9]+$"
#optionsGroup: #_base & {
imports: [...string] | *([])
handle: #handle
handle: #handle
title?: string
description?: string
title: string | *handle
description?: string
env: #_ENV | *(strings.ToUpper(strings.Replace(handle, "-", "_", -1)))
env: #_ENV | *(strings.ToUpper(strings.Replace(handle, "-", "_", -1)))
_envPrefix: env
options: {
[_opt=_]: #option & {
handle: _opt
env: #_ENV | *(_envPrefix + "_" + strings.ToUpper(strings.Replace(handle, " ", "_", -1)))
handle: _opt
env: #_ENV | *(_envPrefix + "_" + strings.ToUpper(strings.Replace(handle, " ", "_", -1)))
}
}
}
#option: {
handle: #handle
handle: #handle
_words: strings.Replace(strings.Replace(strings.Replace(handle, "-", " ", -1), "_", " ", -1), ".", " ", -1)
// lowercased (unexported, golang) identifier
@@ -36,8 +36,14 @@ import (
// upercased (exported, golang) identifier
expIdent: #expIdent | *strings.Replace(strings.ToTitle(_words), " ", "", -1)
type: string | *"string"
type: string | *"string"
description?: string
default?: string
// Default expression to be used
defaultGoExpr?: string
env?: #_ENV
// Plain default value to use when generating .env.example
defaultValue?: string
}