dagger input bool implementation
Signed-off-by: Guillaume de Rouville <guillaume.derouville@gmail.com>
This commit is contained in:
38
cmd/dagger/cmd/input/bool.go
Normal file
38
cmd/dagger/cmd/input/bool.go
Normal file
@@ -0,0 +1,38 @@
|
||||
package input
|
||||
|
||||
import (
|
||||
"github.com/spf13/cobra"
|
||||
"github.com/spf13/viper"
|
||||
"go.dagger.io/dagger/cmd/dagger/logger"
|
||||
"go.dagger.io/dagger/state"
|
||||
)
|
||||
|
||||
var boolCmd = &cobra.Command{
|
||||
Use: "bool <TARGET> <true|false>",
|
||||
Short: "Add a boolean input",
|
||||
Args: cobra.ExactArgs(2),
|
||||
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())
|
||||
|
||||
updateEnvironmentInput(
|
||||
ctx,
|
||||
cmd,
|
||||
args[0],
|
||||
state.BoolInput(readInput(ctx, args[1])),
|
||||
)
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
if err := viper.BindPFlags(boolCmd.Flags()); err != nil {
|
||||
panic(err)
|
||||
}
|
||||
}
|
@@ -31,6 +31,7 @@ func init() {
|
||||
jsonCmd,
|
||||
yamlCmd,
|
||||
listCmd,
|
||||
boolCmd,
|
||||
unsetCmd,
|
||||
)
|
||||
}
|
||||
|
Reference in New Issue
Block a user