# # # add_dir "tests/invoke_subcommands" # # add_file "tests/invoke_subcommands/__driver__.lua" # content [bc08b90e9cb3a7cc52c7f895f59df021b7265498] # # patch "commands.cc" # from [dd318c5ee0564c0745c5c6dec455be4c573e54ba] # to [a2d0c96cffa70e506ac24e909e9fd85f0bf656e4] # ============================================================ --- tests/invoke_subcommands/__driver__.lua bc08b90e9cb3a7cc52c7f895f59df021b7265498 +++ tests/invoke_subcommands/__driver__.lua bc08b90e9cb3a7cc52c7f895f59df021b7265498 @@ -0,0 +1,16 @@ + +mtn_setup() + +-- Invoking a command with an unknown subcommand shows the correct error. +check(mtn("list", "foobar"), 1, "", true) +output = readfile("stderr") +check(string.find(output, "could not match 'foobar'") ~= nil) +check(string.find(output, "to a subcommand of 'list'") ~= nil) + +-- Invoking a command with a missing subcommand shows the correct error. +check(mtn("list"), 1, "", true) +output = readfile("stderr") +check(string.find(output, "no subcommand specified for 'list'") ~= nil) + +-- Invoking a command with a correct subcommand works. +check(mtn("list", "keys"), 0, false, "") ============================================================ --- commands.cc dd318c5ee0564c0745c5c6dec455be4c573e54ba +++ commands.cc a2d0c96cffa70e506ac24e909e9fd85f0bf656e4 @@ -647,17 +647,20 @@ namespace commands { command * cmd = CMD_REF(__root__)->find_command(ident); + string visibleid = join_words(vector< utf8 >(ident.begin() + 1, + ident.end()))(); + N(!(!cmd->is_leaf() && cmd->parent() == CMD_REF(__root__)), F("command '%s' is invalid; it is a group") % join_words(ident)); N(!(!cmd->is_leaf() && args.empty()), - F("no subcommand specified for '%s'") % join_words(ident)); + F("no subcommand specified for '%s'") % visibleid); N(!(!cmd->is_leaf() && !args.empty()), F("could not match '%s' to a subcommand of '%s'") % - join_words(args) % join_words(ident)); + join_words(args) % visibleid); - L(FL("executing command '%s'") % join_words(ident)); + L(FL("executing command '%s'") % visibleid); // at this point we process the data from _MTN/options if // the command needs it.