dagger: unset input

Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
Tom Chauveau 2021-04-29 17:06:59 +02:00
parent 9d421c6c42
commit ced9ab07e5
2 changed files with 44 additions and 0 deletions

View File

@ -28,6 +28,7 @@ func init() {
jsonCmd,
yamlCmd,
listCmd,
unsetCmd,
)
}
@ -79,3 +80,20 @@ func readInput(ctx context.Context, source string) string {
return string(data)
}
func removeEnvironmentInput(ctx context.Context, key string) {
lg := log.Ctx(ctx)
store, err := dagger.DefaultStore()
if err != nil {
lg.Fatal().Err(err).Msg("failed to load store")
}
st := common.GetCurrentEnvironmentState(ctx, store)
st.RemoveInputs(key)
if err := store.UpdateEnvironment(ctx, st, nil); err != nil {
lg.Fatal().Err(err).Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("cannot update environment")
}
lg.Info().Str("environmentId", st.ID).Str("environmentName", st.Name).Msg("updated environment")
}

View File

@ -0,0 +1,26 @@
package input
import (
"dagger.io/go/cmd/dagger/logger"
"github.com/spf13/cobra"
"github.com/spf13/viper"
)
var unsetCmd = &cobra.Command{
Use: "unset [TARGET]",
Short: "Remove input of an environment",
Args: cobra.ExactArgs(1),
PreRun: func(cmd *cobra.Command, args []string) {
// Fix Viper bug for duplicate flags:
// https://github.com/spf13/viper/issues/233
if err := viper.BindPFlags(cmd.Flags()); err != nil {
panic(err)
}
},
Run: func(cmd *cobra.Command, args []string) {
lg := logger.New()
ctx := lg.WithContext(cmd.Context())
removeEnvironmentInput(ctx, args[0])
},
}