forked from qt-creator/qt-creator
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:
@@ -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;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user