commit
8abf06cb9b
@ -28,6 +28,7 @@ func init() {
|
|||||||
jsonCmd,
|
jsonCmd,
|
||||||
yamlCmd,
|
yamlCmd,
|
||||||
listCmd,
|
listCmd,
|
||||||
|
unsetCmd,
|
||||||
)
|
)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
39
cmd/dagger/cmd/input/unset.go
Normal file
39
cmd/dagger/cmd/input/unset.go
Normal file
@ -0,0 +1,39 @@
|
|||||||
|
package input
|
||||||
|
|
||||||
|
import (
|
||||||
|
"dagger.io/go/cmd/dagger/cmd/common"
|
||||||
|
"dagger.io/go/cmd/dagger/logger"
|
||||||
|
"dagger.io/go/dagger"
|
||||||
|
"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())
|
||||||
|
|
||||||
|
store, err := dagger.DefaultStore()
|
||||||
|
if err != nil {
|
||||||
|
lg.Fatal().Err(err).Msg("failed to load store")
|
||||||
|
}
|
||||||
|
|
||||||
|
st := common.GetCurrentEnvironmentState(ctx, store)
|
||||||
|
st.RemoveInputs(args[0])
|
||||||
|
|
||||||
|
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")
|
||||||
|
},
|
||||||
|
}
|
@ -119,6 +119,13 @@ setup() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output '"my input"'
|
assert_output '"my input"'
|
||||||
|
|
||||||
|
# unset simple input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# nested input
|
# nested input
|
||||||
"$DAGGER" input -e "input" text "nested.input" "nested input"
|
"$DAGGER" input -e "input" text "nested.input" "nested input"
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
@ -128,6 +135,13 @@ setup() {
|
|||||||
"input": "nested input"
|
"input": "nested input"
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset nested input
|
||||||
|
"$DAGGER" input -e "input" unset "nested.input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" nested
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# file input
|
# file input
|
||||||
"$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/input.txt
|
"$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/input.txt
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
@ -135,6 +149,13 @@ setup() {
|
|||||||
assert_success
|
assert_success
|
||||||
assert_output '"from file\n"'
|
assert_output '"from file\n"'
|
||||||
|
|
||||||
|
# unset file input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
# invalid file
|
# invalid file
|
||||||
run "$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/notexist
|
run "$DAGGER" input -e "input" text "input" -f "$TESTDIR"/cli/input/simple/testdata/notexist
|
||||||
assert_failure
|
assert_failure
|
||||||
@ -145,11 +166,19 @@ setup() {
|
|||||||
run "$DAGGER" -l error query -e "input" input
|
run "$DAGGER" -l error query -e "input" input
|
||||||
assert_success
|
assert_success
|
||||||
assert_output '"from stdin"'
|
assert_output '"from stdin"'
|
||||||
|
|
||||||
|
# unset stdin input
|
||||||
|
"$DAGGER" input -e "input" unset "input"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" input
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input json" {
|
@test "dagger input json" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
||||||
|
|
||||||
|
# simple json
|
||||||
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" json "structured" '{"a": "foo", "b": 42}'
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -159,6 +188,14 @@ setup() {
|
|||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset simple json
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
|
# json from file
|
||||||
"$DAGGER" input -e "input" json "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.json
|
"$DAGGER" input -e "input" json "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.json
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -167,11 +204,19 @@ setup() {
|
|||||||
"a": "from file",
|
"a": "from file",
|
||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset json from file
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input yaml" {
|
@test "dagger input yaml" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/simple "input"
|
||||||
|
|
||||||
|
# simple yaml
|
||||||
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
"$DAGGER" input -e "input" yaml "structured" '{"a": "foo", "b": 42}'
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -181,6 +226,14 @@ setup() {
|
|||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset simple yaml
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
|
|
||||||
|
# yaml from file
|
||||||
"$DAGGER" input -e "input" yaml "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.yaml
|
"$DAGGER" input -e "input" yaml "structured" -f "$TESTDIR"/cli/input/simple/testdata/input.yaml
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input" structured
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
@ -189,11 +242,19 @@ setup() {
|
|||||||
"a": "from file",
|
"a": "from file",
|
||||||
"b": 42
|
"b": 42
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset yaml from file
|
||||||
|
"$DAGGER" input -e "input" unset "structured"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input" structured
|
||||||
|
assert_success
|
||||||
|
assert_output 'null'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input dir" {
|
@test "dagger input dir" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
||||||
|
|
||||||
|
# input dir
|
||||||
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
|
"$DAGGER" input -e "input" dir "source" "$TESTDIR"/cli/input/artifact/testdata
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input"
|
run "$DAGGER" -l error query -e "input"
|
||||||
@ -203,11 +264,21 @@ setup() {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"source": {}
|
"source": {}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset dir
|
||||||
|
"$DAGGER" input -e "input" unset "source"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input"
|
||||||
|
assert_success
|
||||||
|
assert_output '{
|
||||||
|
"foo": "bar"
|
||||||
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input git" {
|
@test "dagger input git" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/artifact "input"
|
||||||
|
|
||||||
|
# input git
|
||||||
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
|
"$DAGGER" input -e "input" git "source" https://github.com/samalba/dagger-test-simple.git
|
||||||
"$DAGGER" up -e "input"
|
"$DAGGER" up -e "input"
|
||||||
run "$DAGGER" -l error query -e "input"
|
run "$DAGGER" -l error query -e "input"
|
||||||
@ -216,11 +287,20 @@ setup() {
|
|||||||
"foo": "bar",
|
"foo": "bar",
|
||||||
"source": {}
|
"source": {}
|
||||||
}'
|
}'
|
||||||
|
|
||||||
|
# unset input git
|
||||||
|
"$DAGGER" input -e "input" unset "source"
|
||||||
|
"$DAGGER" up -e "input"
|
||||||
|
run "$DAGGER" -l error query -e "input"
|
||||||
|
assert_output '{
|
||||||
|
"foo": "bar"
|
||||||
|
}'
|
||||||
}
|
}
|
||||||
|
|
||||||
@test "dagger input scan" {
|
@test "dagger input scan" {
|
||||||
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
|
"$DAGGER" new --plan-dir "$TESTDIR"/cli/input/scan "scan"
|
||||||
|
|
||||||
|
# TODO "scan" option isn't implemented
|
||||||
run "$DAGGER" input scan -e "input"
|
run "$DAGGER" input scan -e "input"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user