From 1d8834b9b1ec9144e8c8b4a8d345f3d655851d46 Mon Sep 17 00:00:00 2001 From: Richard Jones Date: Tue, 4 Jan 2022 10:23:21 -0700 Subject: [PATCH] implemented --with to fill inputs.params Signed-off-by: Richard Jones --- cmd/dagger/cmd/up.go | 5 ++++- plan/plan.go | 17 ++++++++++++++++- stdlib/europa/dagger/engine/plan.cue | 5 +---- 3 files changed, 21 insertions(+), 6 deletions(-) diff --git a/cmd/dagger/cmd/up.go b/cmd/dagger/cmd/up.go index 721f8af1..b1b14a8f 100644 --- a/cmd/dagger/cmd/up.go +++ b/cmd/dagger/cmd/up.go @@ -24,6 +24,8 @@ import ( "github.com/spf13/viper" ) +var withParams []string + var upCmd = &cobra.Command{ Use: "up", Short: "Bring an environment online with latest plan and inputs", @@ -142,7 +144,7 @@ func checkUniverseVersion(ctx context.Context, projectPath string) bool { func europaUp(ctx context.Context, cl *client.Client, args ...string) error { lg := log.Ctx(ctx) - p, err := plan.Load(ctx, args...) + p, err := plan.Load(ctx, withParams, args...) if err != nil { lg.Fatal().Err(err).Msg("failed to load plan") } @@ -220,6 +222,7 @@ func checkInputs(ctx context.Context, env *environment.Environment) error { func init() { upCmd.Flags().BoolP("force", "f", false, "Force up, disable inputs check") upCmd.Flags().String("output", "", "Write computed output. Prints on stdout if set to-") + upCmd.Flags().StringArrayVarP(&withParams, "with", "w", []string{}, "") if err := viper.BindPFlags(upCmd.Flags()); err != nil { panic(err) diff --git a/plan/plan.go b/plan/plan.go index 659b79d6..fe6e7581 100644 --- a/plan/plan.go +++ b/plan/plan.go @@ -23,7 +23,7 @@ type Plan struct { source *compiler.Value } -func Load(ctx context.Context, args ...string) (*Plan, error) { +func Load(ctx context.Context, withParams []string, args ...string) (*Plan, error) { log.Ctx(ctx).Debug().Interface("args", args).Msg("loading plan") // FIXME: universe vendoring @@ -36,6 +36,21 @@ func Load(ctx context.Context, args ...string) (*Plan, error) { return nil, err } + if len(withParams) > 0 { + for i, param := range withParams { + log.Ctx(ctx).Debug().Interface("with", param).Msg("applying parameter") + paramV, err := compiler.Compile(fmt.Sprintf("with%v", i), param) + if err != nil { + return nil, err + } + + fillErr := v.FillPath(cue.ParsePath("inputs.params"), paramV) + if fillErr != nil { + return nil, err + } + } + } + p := &Plan{ context: plancontext.New(), source: v, diff --git a/stdlib/europa/dagger/engine/plan.cue b/stdlib/europa/dagger/engine/plan.cue index 29b2efaf..20ebce6a 100644 --- a/stdlib/europa/dagger/engine/plan.cue +++ b/stdlib/europa/dagger/engine/plan.cue @@ -12,10 +12,7 @@ package engine // Securely receive secrets secrets: [name=string]: _#inputSecret // Receive runtime parameters - params: { - @dagger(notimplemented) - [name=string]: _ - } + params: [name=string]: _ } // Send outputs to the client