forked from qt-creator/qt-creator
Docker: Simplify and fix "Open Shell in Container"
Change-Id: Icce72712a006f524b8a8328904d89f2b0e2b8a3d Reviewed-by: <github-actions-qt-creator@cristianadam.eu> Reviewed-by: Christian Stenger <christian.stenger@qt.io>
This commit is contained in:
@@ -530,32 +530,29 @@ DockerDevice::DockerDevice(const DockerDeviceData &data)
|
|||||||
setAllowEmptyCommand(true);
|
setAllowEmptyCommand(true);
|
||||||
|
|
||||||
setOpenTerminal([this](const Environment &env, const FilePath &workingDir) {
|
setOpenTerminal([this](const Environment &env, const FilePath &workingDir) {
|
||||||
DeviceProcess * const proc = createProcess(nullptr);
|
Q_UNUSED(env); // TODO: That's the runnable's environment in general. Use it via -e below.
|
||||||
QObject::connect(proc, &DeviceProcess::finished, [proc] {
|
updateContainerAccess();
|
||||||
if (!proc->errorString().isEmpty()) {
|
if (d->m_container.isEmpty()) {
|
||||||
MessageManager::writeDisrupting(
|
MessageManager::writeDisrupting(tr("Error starting remote shell. No container"));
|
||||||
tr("Error running remote shell: %1").arg(proc->errorString()));
|
return;
|
||||||
}
|
}
|
||||||
proc->deleteLater();
|
|
||||||
});
|
QtcProcess *proc = new QtcProcess(QtcProcess::TerminalOn);
|
||||||
|
QObject::connect(proc, &QtcProcess::finished, proc, &QObject::deleteLater);
|
||||||
|
|
||||||
QObject::connect(proc, &DeviceProcess::errorOccurred, [proc] {
|
QObject::connect(proc, &DeviceProcess::errorOccurred, [proc] {
|
||||||
MessageManager::writeDisrupting(tr("Error starting remote shell."));
|
MessageManager::writeDisrupting(tr("Error starting remote shell."));
|
||||||
proc->deleteLater();
|
proc->deleteLater();
|
||||||
});
|
});
|
||||||
|
|
||||||
Runnable runnable;
|
const QString wd = workingDir.isEmpty() ? "/" : workingDir.path();
|
||||||
runnable.command = {"/bin/sh", {}};
|
proc->setCommand({"docker", {"exec", "-it", "-w", wd, d->m_container, "/bin/sh"}});
|
||||||
runnable.device = sharedFromThis();
|
proc->setEnvironment(Environment::systemEnvironment()); // The host system env. Intentional.
|
||||||
runnable.environment = env;
|
proc->start();
|
||||||
runnable.workingDirectory = workingDir;
|
|
||||||
runnable.extraData[Constants::DOCKER_RUN_FLAGS] = QStringList({"--interactive", "--tty"});
|
|
||||||
|
|
||||||
proc->setRunInTerminal(true);
|
|
||||||
proc->start(runnable);
|
|
||||||
});
|
});
|
||||||
|
|
||||||
if (HostOsInfo::isAnyUnixHost()) {
|
if (HostOsInfo::isAnyUnixHost()) {
|
||||||
addDeviceAction({tr("Open Shell in Container"), [](const IDevice::Ptr &device, QWidget *) {
|
addDeviceAction({tr("Open Shell in Container"), [this](const IDevice::Ptr &device, QWidget *) {
|
||||||
device->openTerminal(Environment(), FilePath());
|
device->openTerminal(Environment(), FilePath());
|
||||||
}});
|
}});
|
||||||
}
|
}
|
||||||
|
Reference in New Issue
Block a user