Skip to content

Commit 2401f90

Browse files
committed
Add --propagate-exit-code option.
Propagate exist code from inner command to driver exit code.
1 parent 7aaa2ff commit 2401f90

File tree

1 file changed

+8
-1
lines changed

1 file changed

+8
-1
lines changed

main.cpp

+8-1
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,7 @@ class Main {
111111

112112
QObject::connect(&process, qOverload<int>(&QProcess::finished), [this](int code) {
113113
const QByteArray msg = QString("*exited:%0").arg(code).toUtf8();
114+
exitCode = code;
114115
write(controlFd, msg.data(), msg.size() + 1);
115116
if (autoQuit) {
116117
QCoreApplication::instance()->quit();
@@ -123,6 +124,10 @@ class Main {
123124
process.start();
124125
}
125126

127+
int getExitCode() {
128+
return exitCode;
129+
}
130+
126131
private:
127132
void sendToInterior(char* data, ssize_t len) {
128133
::write(process.masterFd, data, static_cast<size_t>(len));
@@ -308,6 +313,7 @@ class Main {
308313
QByteArray pendingControlData;
309314
VTermScreenCallbacks screenCallbacks;
310315
VTermStateFallbacks unhandled;
316+
int exitCode = 22;
311317

312318
// buffered screen state
313319
bool cursorVisible = true;
@@ -338,6 +344,7 @@ int main(int argc, char** argv) {
338344
parser.setOptionsAfterPositionalArgumentsMode(QCommandLineParser::ParseAsPositionalArguments);
339345
parser.addPositionalArgument("command", "Command to execute and connect to the terminal");
340346
parser.addOption({ "control-via-fd0", "control communication is via fd 0."});
347+
parser.addOption({ "propagate-exit-code", "Propagate exist code from inner command to driver exit code."});
341348
parser.process(app);
342349
const QStringList args = parser.positionalArguments();
343350

@@ -350,5 +357,5 @@ int main(int argc, char** argv) {
350357

351358
app.exec();
352359

353-
return 0;
360+
return parser.isSet("propagate-exit-code") ? m.getExitCode() : 0;
354361
}

0 commit comments

Comments
 (0)