diff --git a/source/dub/commandline.d b/source/dub/commandline.d index 93c8457..ca5a552 100644 --- a/source/dub/commandline.d +++ b/source/dub/commandline.d @@ -465,9 +465,22 @@ } if (cmd is null) { + logInfoNoTag("USAGE: dub [--version] [] [] [-- []]"); + logInfoNoTag(""); logError("Unknown command: %s", command_name_argument.value); - writeln(); - showHelp(handler.commandGroups, common_args); + import std.algorithm.iteration : filter; + import std.uni : toUpper; + foreach (CommandGroup key; handler.commandGroups) + { + foreach (Command command; key.commands) + { + if (levenshteinDistance(command_name_argument.value, command.name) < 4) { + logInfo("Did you mean '%s'?", command.name); + } + } + } + + logInfoNoTag(""); return 1; } diff --git a/test/issue2574-mistyping-commands.sh b/test/issue2574-mistyping-commands.sh new file mode 100755 index 0000000..b239a2a --- /dev/null +++ b/test/issue2574-mistyping-commands.sh @@ -0,0 +1,17 @@ +#!/usr/bin/env bash + +. $(dirname "${BASH_SOURCE[0]}")/common.sh + +$DUB upfrade 2>&1 >/dev/null && die $LINENO '"dub upfrade" should not succeed' + +if [ "$($DUB upfrade 2>&1 | grep -Fc "Unknown command: upfrade")" != "1" ]; then + die $LINENO 'Missing Unknown command line' +fi + +if [ "$($DUB upfrade 2>&1 | grep -Fc "Did you mean 'upgrade'?")" != "1" ]; then + die $LINENO 'Missing upgrade suggestion' +fi + +if [ "$($DUB upfrade 2>&1 | grep -Fc "build")" != "0" ]; then + die $LINENO 'Did not expect to see build as a suggestion and did not want a full list of commands' +fi