@@ -13,10 +13,12 @@ import (
1313 "net/http"
1414 "path"
1515 "path/filepath"
16+ "strings"
1617 "sync"
1718 "sync/atomic"
1819 "time"
1920
21+ "github.com/BurntSushi/toml"
2022 "github.com/Masterminds/sprig/v3"
2123 "github.com/claceio/clace/internal/app/appfs"
2224 "github.com/claceio/clace/internal/app/apptype"
@@ -71,6 +73,7 @@ type App struct {
7173 sseListeners []chan SSEMessage
7274 funcMap template.FuncMap
7375 starlarkCache map [string ]* starlarkCacheEntry
76+ appDefaults types.AppDefaults
7477}
7578
7679type starlarkCacheEntry struct {
@@ -85,7 +88,7 @@ type SSEMessage struct {
8588
8689func NewApp (sourceFS * appfs.SourceFs , workFS * appfs.WorkFs , logger * types.Logger ,
8790 appEntry * types.AppEntry , systemConfig * types.SystemConfig ,
88- plugins map [string ]types.PluginSettings ) * App {
91+ plugins map [string ]types.PluginSettings , appDefaults types. AppDefaults ) ( * App , error ) {
8992 newApp := & App {
9093 sourceFS : sourceFS ,
9194 Logger : logger ,
@@ -94,6 +97,10 @@ func NewApp(sourceFS *appfs.SourceFs, workFS *appfs.WorkFs, logger *types.Logger
9497 starlarkCache : map [string ]* starlarkCacheEntry {},
9598 }
9699 newApp .plugins = NewAppPlugins (newApp , plugins , appEntry .Metadata .Accounts )
100+ newApp .appDefaults = appDefaults
101+ if err := newApp .updateAppDefaults (); err != nil {
102+ return nil , err
103+ }
97104
98105 if appEntry .IsDev {
99106 newApp .appDev = dev .NewAppDev (logger , & appfs.WritableSourceFs {SourceFs : sourceFS }, workFS , systemConfig )
@@ -119,7 +126,7 @@ func NewApp(sourceFS *appfs.SourceFs, workFS *appfs.WorkFs, logger *types.Logger
119126 delete (funcMap , "expandenv" )
120127
121128 newApp .funcMap = funcMap
122- return newApp
129+ return newApp , nil
123130}
124131
125132func (a * App ) Initialize (dryRun DryRun ) error {
@@ -694,3 +701,19 @@ func (a *App) loadStarlark(thread *starlark.Thread, module string, cache map[str
694701 }
695702 return cacheEntry .globals , cacheEntry .err
696703}
704+
705+ // updateAppDefaults updates the app defaults from the metadata
706+ // It creates a TOML intermediate string so that the TOML parsing can be used
707+ func (a * App ) updateAppDefaults () error {
708+ if len (a .Metadata .AppDefaults ) == 0 {
709+ return nil
710+ }
711+
712+ buf := strings.Builder {}
713+ for key , value := range a .Metadata .AppDefaults {
714+ buf .WriteString (fmt .Sprintf ("%s=\" %s\" \n " , key , value ))
715+ }
716+
717+ _ , err := toml .Decode (buf .String (), & a .appDefaults )
718+ return err
719+ }
0 commit comments