Skip to content

Commit

Permalink
feat(createSshConnection): add environment variable support to exec m…
Browse files Browse the repository at this point in the history
…ethod
  • Loading branch information
markwylde committed Nov 17, 2023
1 parent 3bca9a3 commit 73d7727
Showing 1 changed file with 17 additions and 1 deletion.
18 changes: 17 additions & 1 deletion lib/utils/createSshConnection.js
Original file line number Diff line number Diff line change
Expand Up @@ -149,7 +149,23 @@ export async function createSshConnection({ host, username, port = 22, privateKe
interactive,
script: (scriptContent, onData) => script(scriptContent, onData, false),
sudoScript: (scriptContent, onData) => script(scriptContent, onData, true),
exec: (command, onData) => execRemote(connObj, command, onData, config),
exec: (command, optionsOrOnData, onData) => {
if (typeof optionsOrOnData === 'function') {
onData = optionsOrOnData;
optionsOrOnData = {};
}

let envString = '';
if (optionsOrOnData?.env) {
for (const [key, value] of Object.entries(optionsOrOnData.env)) {
envString += `${key}='${value}' `;
}
}

const fullCommand = `${envString}${command}`;

return execRemote(connObj, fullCommand, onData, config);
},
close: () => {
return new Promise(resolve => {
connObj.once('close', resolve);
Expand Down

0 comments on commit 73d7727

Please sign in to comment.