Differential D10469 Diff 33748 src/applications/drydock/management/DrydockManagementRunCommandWorkflow.php
Changeset View
Changeset View
Standalone View
Standalone View
src/applications/drydock/management/DrydockManagementRunCommandWorkflow.php
- This file was added.
<?php | |||||
final class DrydockManagementRunCommandWorkflow | |||||
extends DrydockManagementWorkflow { | |||||
protected function didConstruct() { | |||||
$this | |||||
->setName('run-command') | |||||
->setSynopsis(pht('Run a command on a remote host.')) | |||||
->setArguments( | |||||
array( | |||||
array( | |||||
'name' => 'id', | |||||
'param' => 'lease', | |||||
'help' => 'The Drydock lease ID.', | |||||
), | |||||
array( | |||||
'name' => 'command', | |||||
'param' => 'command', | |||||
'help' => 'The command to run on the remote host.', | |||||
), | |||||
)); | |||||
} | |||||
public function execute(PhutilArgumentParser $args) { | |||||
$console = PhutilConsole::getConsole(); | |||||
$id = $args->getArg('id'); | |||||
if (!$id) { | |||||
throw new PhutilArgumentUsageException(pht( | |||||
'Specify a lease ID to run the command on.')); | |||||
} | |||||
$viewer = $this->getViewer(); | |||||
$lease = id(new DrydockLeaseQuery()) | |||||
->setViewer($viewer) | |||||
->withIDs(array($id)) | |||||
->executeOne(); | |||||
if (!$lease) { | |||||
$console->writeErr("Lease %d does not exist!\n", $id); | |||||
return 1; | |||||
} else { | |||||
$interface = $lease->getInterface('command'); | |||||
$future = $interface->getExecFuture('%C', $args->getArg('command')); | |||||
list($err, $stdout, $stderr) = $future->resolve(); | |||||
$console->writeOut('%s', $stdout); | |||||
$console->writeErr('%s', $stderr); | |||||
return $err; | |||||
} | |||||
} | |||||
} |