Utils: Allow Os Type selection for CommandLine

Adds function overloads allowing users to choose the flavor of
command line argument quoting.

Change-Id: I24518162c286114333a93301fedc2a3329cd0c29
Reviewed-by: hjk <hjk@qt.io>
This commit is contained in:
Marcus Tillmanns
2022-10-18 09:50:34 +02:00
parent ce6ab1a14d
commit 9498b736da
2 changed files with 20 additions and 0 deletions

View File

@@ -1412,6 +1412,12 @@ CommandLine::CommandLine(const FilePath &exe, const QStringList &args)
addArgs(args); addArgs(args);
} }
CommandLine::CommandLine(const FilePath &exe, const QStringList &args, OsType osType)
: m_executable(exe)
{
addArgs(args, osType);
}
CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType) CommandLine::CommandLine(const FilePath &exe, const QString &args, RawType)
: m_executable(exe) : m_executable(exe)
{ {
@@ -1438,12 +1444,23 @@ void CommandLine::addArg(const QString &arg)
ProcessArgs::addArg(&m_arguments, arg, m_executable.osType()); ProcessArgs::addArg(&m_arguments, arg, m_executable.osType());
} }
void CommandLine::addArg(const QString &arg, OsType osType)
{
ProcessArgs::addArg(&m_arguments, arg, osType);
}
void CommandLine::addArgs(const QStringList &inArgs) void CommandLine::addArgs(const QStringList &inArgs)
{ {
for (const QString &arg : inArgs) for (const QString &arg : inArgs)
addArg(arg); addArg(arg);
} }
void CommandLine::addArgs(const QStringList &inArgs, OsType osType)
{
for (const QString &arg : inArgs)
addArg(arg, osType);
}
// Adds cmd's executable and arguments one by one to this commandline. // Adds cmd's executable and arguments one by one to this commandline.
// Useful for 'sudo', 'nice', etc // Useful for 'sudo', 'nice', etc
void CommandLine::addCommandLineAsArgs(const CommandLine &cmd) void CommandLine::addCommandLineAsArgs(const CommandLine &cmd)

View File

@@ -115,12 +115,15 @@ public:
CommandLine(); CommandLine();
explicit CommandLine(const FilePath &executable); explicit CommandLine(const FilePath &executable);
CommandLine(const FilePath &exe, const QStringList &args); CommandLine(const FilePath &exe, const QStringList &args);
CommandLine(const FilePath &exe, const QStringList &args, OsType osType);
CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType); CommandLine(const FilePath &exe, const QString &unparsedArgs, RawType);
static CommandLine fromUserInput(const QString &cmdline, MacroExpander *expander = nullptr); static CommandLine fromUserInput(const QString &cmdline, MacroExpander *expander = nullptr);
void addArg(const QString &arg); void addArg(const QString &arg);
void addArg(const QString &arg, OsType osType);
void addArgs(const QStringList &inArgs); void addArgs(const QStringList &inArgs);
void addArgs(const QStringList &inArgs, OsType osType);
void addArgs(const QString &inArgs, RawType); void addArgs(const QString &inArgs, RawType);
void prependArgs(const QStringList &inArgs); void prependArgs(const QStringList &inArgs);