Improve dagger input UX (solve #874)
Add new argument `--show-optional` to `dagger input list`. Now by default, `dagger input list` will only show required input. To get all inputs (including those with default value), you can use that new argument. Test has been updated to support changes. Signed-off-by: Tom Chauveau <tom.chauveau@epitech.eu>
This commit is contained in:
parent
3b5b83012a
commit
3c1c0f13f6
@ -62,6 +62,13 @@ var listCmd = &cobra.Command{
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
if !viper.GetBool("show-optional") && !viper.GetBool("all") {
|
||||||
|
// skip input if there is already a default value
|
||||||
|
if hasDefault {
|
||||||
|
continue
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
fmt.Fprintf(w, "%s\t%s\t%t\t%s\n",
|
fmt.Fprintf(w, "%s\t%s\t%t\t%s\n",
|
||||||
inp.Path(),
|
inp.Path(),
|
||||||
common.FormatValue(inp),
|
common.FormatValue(inp),
|
||||||
@ -95,6 +102,7 @@ func isUserSet(env *state.State, val *compiler.Value) bool {
|
|||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
listCmd.Flags().BoolP("all", "a", false, "List all inputs (include non-overridable)")
|
listCmd.Flags().BoolP("all", "a", false, "List all inputs (include non-overridable)")
|
||||||
|
listCmd.Flags().Bool("show-optional", false, "List optional inputs (those with default values)")
|
||||||
|
|
||||||
if err := viper.BindPFlags(listCmd.Flags()); err != nil {
|
if err := viper.BindPFlags(listCmd.Flags()); err != nil {
|
||||||
panic(err)
|
panic(err)
|
||||||
|
@ -364,28 +364,41 @@ setup() {
|
|||||||
"$DAGGER" input text cfg.str "foobar" -e "list"
|
"$DAGGER" input text cfg.str "foobar" -e "list"
|
||||||
|
|
||||||
out="$("$DAGGER" input list -e "list")"
|
out="$("$DAGGER" input list -e "list")"
|
||||||
|
outOpt="$("$DAGGER" input list --show-optional -e "list")"
|
||||||
outAll="$("$DAGGER" input list --all -e "list")"
|
outAll="$("$DAGGER" input list --all -e "list")"
|
||||||
|
|
||||||
#note: this is the recommended way to use pipes with bats
|
#note: this is the recommended way to use pipes with bats
|
||||||
run bash -c "echo \"$out\" | grep awsConfig.accessKey | grep 'dagger.#Secret' | grep 'AWS access key'"
|
run bash -c "echo \"$out\" | grep awsConfig.accessKey | grep 'dagger.#Secret' | grep false | grep 'AWS access key'"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
run bash -c "echo \"$out\" | grep cfgInline.source | grep 'dagger.#Artifact' | grep false | grep 'source dir'"
|
run bash -c "echo \"$out\" | grep cfgInline.source | grep 'dagger.#Artifact' | grep false | grep 'source dir'"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
|
run bash -c "echo \"$outOpt\" | grep awsConfig.accessKey | grep 'dagger.#Secret' | grep 'AWS access key'"
|
||||||
|
assert_success
|
||||||
|
|
||||||
|
run bash -c "echo \"$outOpt\" | grep cfgInline.source | grep 'dagger.#Artifact' | grep false | grep 'source dir'"
|
||||||
|
assert_success
|
||||||
|
|
||||||
run bash -c "echo \"$outAll\" | grep cfg2"
|
run bash -c "echo \"$outAll\" | grep cfg2"
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
run bash -c "echo \"$out\" | grep cfgInline.strDef | grep '*yolo | string' | grep false"
|
run bash -c "echo \"$out\" | grep cfgInline.strDef | grep '*yolo | string' | grep false"
|
||||||
|
assert_failure
|
||||||
|
|
||||||
|
run bash -c "echo \"$outOpt\" | grep cfgInline.strDef | grep '*yolo | string' | grep false"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
run bash -c "echo \"$out\" | grep cfg.num"
|
run bash -c "echo \"$out\" | grep cfg.num"
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
|
run bash -c "echo \"$outOpt\" | grep cfg.num"
|
||||||
|
assert_failure
|
||||||
|
|
||||||
run bash -c "echo \"$outAll\" | grep cfg.num | grep 21 | grep -v int"
|
run bash -c "echo \"$outAll\" | grep cfg.num | grep 21 | grep -v int"
|
||||||
assert_success
|
assert_success
|
||||||
|
|
||||||
run bash -c "echo \"$out\" | grep cfg.strSet"
|
run bash -c "echo \"$outOpt\" | grep cfg.strSet"
|
||||||
assert_failure
|
assert_failure
|
||||||
|
|
||||||
run bash -c "echo \"$outAll\" | grep cfg.strSet | grep pipo"
|
run bash -c "echo \"$outAll\" | grep cfg.strSet | grep pipo"
|
||||||
|
@ -20,7 +20,7 @@ setup() {
|
|||||||
dagger_new_with_plan test-core "$TESTDIR"/core/inputs-outputs
|
dagger_new_with_plan test-core "$TESTDIR"/core/inputs-outputs
|
||||||
|
|
||||||
# List available inputs
|
# List available inputs
|
||||||
run dagger -e test-core input list
|
run dagger -e test-core input list --show-optional
|
||||||
assert_success
|
assert_success
|
||||||
assert_output --partial 'name'
|
assert_output --partial 'name'
|
||||||
assert_output --partial 'dir'
|
assert_output --partial 'dir'
|
||||||
|
Reference in New Issue
Block a user