From 0c582d95316fed56c83ce407ca17472b5d8f808c Mon Sep 17 00:00:00 2001 From: WebFreak001 Date: Wed, 11 Jan 2023 01:09:10 +0100 Subject: [PATCH] allow entering allowed input in `dub init` --- source/dub/commandline.d | 2 +- test/0-init-interactive.sh | 6 ++++-- 2 files changed, 5 insertions(+), 3 deletions(-) diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 0126061da..31a5ae483 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -1019,7 +1019,7 @@ class InitCommand : Command { if (option_idx < options.length) return options[option_idx]; } - else if (free_choice) + else if (free_choice || options.canFind(choice)) return choice; logError("Select an option between 1 and %u%s.", options.length, free_choice ? " or enter a custom value" : null); diff --git a/test/0-init-interactive.sh b/test/0-init-interactive.sh index 0b38aa5ef..d88203b0f 100755 --- a/test/0-init-interactive.sh +++ b/test/0-init-interactive.sh @@ -27,8 +27,10 @@ function runTest { runTest '0\ntest\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.dub.sdl # select package format out of bounds runTest '3\n0\ntest\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.dub.sdl -# select package format not numeric -runTest 'sdl\n0\ntest\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.dub.sdl +# select package format not numeric, but in list +runTest 'sdl\ntest\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.dub.sdl +# selected value not numeric and not in list +runTest 'sdlf\n0\ntest\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.dub.sdl # default name runTest '0\n\ndesc\nauthor\ngpl\ncopy\n\n' 0-init-interactive.default_name.dub.sdl # json package format