aboutsummaryrefslogtreecommitdiffstats
path: root/src/libs
diff options
context:
space:
mode:
authorMarcus Tillmanns <marcus.tillmanns@qt.io>2022-11-22 08:35:43 +0100
committerMarcus Tillmanns <marcus.tillmanns@qt.io>2022-11-22 13:17:00 +0000
commit3e6c3d9fe7328e824fab14a201c6560cb8bda94f (patch)
treec7c3717d5699f8ce9cc9faccdefeb0bed2b44d9e /src/libs
parentb1df55426a23b60da79316090ea07c8f1b56cc10 (diff)
Utils: Add "addCommandLine..." functions
addCommandLineAsSingleArg allows to reliably create commandlines like "bash -c 'echo ...'" addCommandLineWithAnd combines two command lines by adding '&&' in between Change-Id: Ic5af34c90fd5271dced40ba1341a3df019ededb8 Reviewed-by: hjk <hjk@qt.io>
Diffstat (limited to 'src/libs')
-rw-r--r--src/libs/utils/commandline.cpp20
-rw-r--r--src/libs/utils/commandline.h3
2 files changed, 23 insertions, 0 deletions
diff --git a/src/libs/utils/commandline.cpp b/src/libs/utils/commandline.cpp
index 41aa9b29bd..6ee998fbff 100644
--- a/src/libs/utils/commandline.cpp
+++ b/src/libs/utils/commandline.cpp
@@ -1473,6 +1473,26 @@ void CommandLine::addCommandLineAsArgs(const CommandLine &cmd, RawType)
addArgs(cmd.arguments(), Raw);
}
+void CommandLine::addCommandLineAsSingleArg(const CommandLine &cmd)
+{
+ QString combined;
+ ProcessArgs::addArg(&combined, cmd.executable().path());
+ ProcessArgs::addArgs(&combined, cmd.arguments());
+
+ addArg(combined);
+}
+
+void CommandLine::addCommandLineWithAnd(const CommandLine &cmd)
+{
+ if (m_executable.isEmpty()) {
+ *this = cmd;
+ return;
+ }
+
+ addArgs("&&", Raw);
+ addCommandLineAsArgs(cmd);
+}
+
void CommandLine::addArgs(const QString &inArgs, RawType)
{
ProcessArgs::addArgs(&m_arguments, inArgs);
diff --git a/src/libs/utils/commandline.h b/src/libs/utils/commandline.h
index 67e08b7fe4..68ac27eced 100644
--- a/src/libs/utils/commandline.h
+++ b/src/libs/utils/commandline.h
@@ -132,6 +132,9 @@ public:
void addCommandLineAsArgs(const CommandLine &cmd);
void addCommandLineAsArgs(const CommandLine &cmd, RawType);
+ void addCommandLineAsSingleArg(const CommandLine &cmd);
+ void addCommandLineWithAnd(const CommandLine &cmd);
+
QString toUserOutput() const;
QString displayName() const;