cmd: implemented input validation when updating environment
Signed-off-by: Sam Alba <sam.alba@gmail.com>
This commit is contained in:
parent
d4c8350c08
commit
b37db8eedb
@ -8,7 +8,10 @@ import (
|
||||
"github.com/rs/zerolog/log"
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/client"
|
||||
"go.dagger.io/dagger/cmd/dagger/cmd/common"
|
||||
"go.dagger.io/dagger/environment"
|
||||
"go.dagger.io/dagger/solver"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
@ -32,13 +35,26 @@ func init() {
|
||||
)
|
||||
}
|
||||
|
||||
func updateEnvironmentInput(ctx context.Context, target string, input state.Input) {
|
||||
func updateEnvironmentInput(ctx context.Context, cl *client.Client, target string, input state.Input) {
|
||||
lg := log.Ctx(ctx)
|
||||
|
||||
workspace := common.CurrentWorkspace(ctx)
|
||||
st := common.CurrentEnvironmentState(ctx, workspace)
|
||||
|
||||
st.SetInput(target, input)
|
||||
|
||||
_, err := cl.Do(ctx, st, func(ctx context.Context, env *environment.Environment, s solver.Solver) error {
|
||||
_, err := env.ScanInputs(ctx, true)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
return nil
|
||||
})
|
||||
|
||||
if err != nil {
|
||||
lg.Fatal().Err(err).Str("environment", st.Name).Msg("invalid input")
|
||||
}
|
||||
|
||||
if err := workspace.Save(ctx, st); err != nil {
|
||||
lg.Fatal().Err(err).Str("environment", st.Name).Msg("cannot update environment")
|
||||
}
|
||||
|
Reference in New Issue
Block a user