@@ -208,33 +208,37 @@ void CommandObjectMultiword::Execute(const char *args_string,
208208 error_msg.append (match);
209209 }
210210 } else {
211- // Rather than simply complaining about the invalid (sub) command,
212- // try to offer some alternatives.
213- // This is especially useful for cases where the user types something
214- // seamingly trivial, such as `breakpoint foo`.
211+ // Try to offer some alternatives to help correct the command.
215212 error_msg.assign (
216213 llvm::Twine (" '" + sub_command + " ' is not a valid subcommand of \" " +
217- GetCommandName () + " \" . Valid subcommands are " +
218- GetTopSubcommands (/* count=*/ 5 ) + " . Use \" help " +
219- GetCommandName () + " \" to find out more." )
214+ GetCommandName () + " \" ." + GetSubcommandsHintText () +
215+ " Use \" help " + GetCommandName () + " \" to find out more." )
220216 .str ());
221217 }
222218 error_msg.append (" \n " );
223219 result.AppendRawError (error_msg.c_str ());
224220}
225221
226- std::string CommandObjectMultiword::GetTopSubcommands ( int count ) {
222+ std::string CommandObjectMultiword::GetSubcommandsHintText ( ) {
227223 if (m_subcommand_dict.empty ())
228- return " <NONE>" ;
229- std::string buffer = " {" ;
224+ return " " ;
225+ const size_t maxCount = 5 ;
226+ size_t i = 0 ;
227+ std::string buffer = " Valid subcommand" ;
228+ buffer.append (m_subcommand_dict.size () > 1 ? " s are:" : " is" );
230229 CommandMap::iterator pos;
231230 for (pos = m_subcommand_dict.begin ();
232- pos != m_subcommand_dict.end () && count > 0 ; ++pos, --count ) {
233- buffer.append (" ' " );
231+ pos != m_subcommand_dict.end () && i < maxCount ; ++pos, ++i ) {
232+ buffer.append (" " );
234233 buffer.append (pos->first );
235- buffer.append (" ' ," );
234+ buffer.append (" ," );
236235 }
237- buffer.append (" ...}" );
236+ if (i < m_subcommand_dict.size ())
237+ buffer.append (" and others" );
238+ else
239+ buffer.pop_back ();
240+
241+ buffer.append (" ." );
238242 return buffer;
239243}
240244
0 commit comments