Skip to content

Commit

Permalink
tom extracted method
Browse files Browse the repository at this point in the history
  • Loading branch information
silverqx committed Aug 7, 2024
1 parent de013ae commit 47de50b
Show file tree
Hide file tree
Showing 2 changed files with 25 additions and 15 deletions.
4 changes: 4 additions & 0 deletions tom/include/tom/application.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -189,6 +189,10 @@ namespace Concerns
/*! Get the command name including the guess command name logic. */
QString getCommandName(const QString &name, CommandNotFound notFound);

/*! If passed non-existent command then show all commands list or error wall. */
[[noreturn]] void
handleEmptyCommandName(const QString &name, CommandNotFound notFound);

/* Early exit during parse command-line */
/*! Display the version information and exits. */
[[noreturn]] void showVersion() const;
Expand Down
36 changes: 21 additions & 15 deletions tom/src/tom/application.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -412,27 +412,33 @@ QString Application::getCommandName(const QString &name, const CommandNotFound n

// If passed a non-existent command then show all commands list or error wall
if (commandName.isEmpty())
switch (notFound) {
T_LIKELY
case ShowCommandsList:
showCommandsList(EXIT_FAILURE);
handleEmptyCommandName(name, notFound); // [[noreturn]]

T_UNLIKELY
case ShowErrorWall:
errorWall(QStringLiteral("Command '%1' is not defined.").arg(name));
return commandName;
}

void Application::handleEmptyCommandName(const QString &name,
const CommandNotFound notFound)
{
switch (notFound) {
T_LIKELY
case ShowCommandsList:
showCommandsList(EXIT_FAILURE);

T_UNLIKELY
case ShowErrorWall:
errorWall(QStringLiteral("Command '%1' is not defined.").arg(name));

exitApplication(EXIT_FAILURE);
exitApplication(EXIT_FAILURE);

default:
default:
#ifndef TINYTOM_DEBUG
throw Exceptions::RuntimeError(
sl("Unexpected value for enum struct CommandNotFound."));
throw Exceptions::RuntimeError(
sl("Unexpected value for enum struct CommandNotFound."));
#else
Q_UNREACHABLE();
Q_UNREACHABLE();
#endif
}

return commandName;
}
}

/* Early exit during parse command-line */
Expand Down

0 comments on commit 47de50b

Please sign in to comment.