Utils: Improve and test CommandLine::fromUserInput

Change-Id: Ia18f5b01d91200e6ad65735496395215c6393533
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: <github-actions-qt-creator@cristianadam.eu>
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2023-03-13 13:56:50 +01:00
parent 2d15be91bf
commit 8f1cbd2e52
2 changed files with 91 additions and 10 deletions

View File

@@ -1429,16 +1429,20 @@ CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
CommandLine CommandLine::fromUserInput(const QString &cmdline, MacroExpander *expander)
{
CommandLine cmd;
const int pos = cmdline.indexOf(' ');
if (pos == -1) {
cmd.m_executable = FilePath::fromString(cmdline);
} else {
cmd.m_executable = FilePath::fromString(cmdline.left(pos));
cmd.m_arguments = cmdline.right(cmdline.length() - pos - 1);
if (expander)
cmd.m_arguments = expander->expand(cmd.m_arguments);
}
if (cmdline.isEmpty())
return {};
QString input = cmdline.trimmed();
QStringList result = ProcessArgs::splitArgs(cmdline, HostOsInfo::hostOs());
if (result.isEmpty())
return {};
auto cmd = CommandLine(FilePath::fromUserInput(result.value(0)), result.mid(1));
if (expander)
cmd.m_arguments = expander->expand(cmd.m_arguments);
return cmd;
}