dagger: unset input
Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
9d421c6c42
commit
ced9ab07e5
@ -28,6 +28,7 @@ func init() {
|
|||||||
jsonCmd,
|
jsonCmd,
|
||||||
yamlCmd,
|
yamlCmd,
|
||||||
listCmd,
|
listCmd,
|
||||||
|
unsetCmd,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -79,3 +80,20 @@ func readInput(ctx context.Context, source string) string {
|
|||||||
|
|
||||||
return string(data)
|
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")
|
||||||
|
}
|
||||||
|
26
cmd/dagger/cmd/input/unset.go
Normal file
26
cmd/dagger/cmd/input/unset.go
Normal 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])
|
||||||
|
},
|
||||||
|
}
|
Reference in New Issue
Block a user