@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.)
hq.recaptime.dev/wiki/Phorge
phorge
phabricator
1<?php
2
3final class DrydockManagementCommandWorkflow
4 extends DrydockManagementWorkflow {
5
6 protected function didConstruct() {
7 $this
8 ->setName('command')
9 ->setSynopsis(pht('Run a command on a leased resource.'))
10 ->setArguments(
11 array(
12 array(
13 'name' => 'lease',
14 'param' => 'id',
15 'help' => pht('Lease ID.'),
16 ),
17 array(
18 'name' => 'argv',
19 'wildcard' => true,
20 'help' => pht('Command to execute.'),
21 ),
22 ));
23 }
24
25 public function execute(PhutilArgumentParser $args) {
26 $lease_id = $args->getArg('lease');
27 if (!$lease_id) {
28 throw new PhutilArgumentUsageException(
29 pht(
30 'Use "--lease" to specify a lease.'));
31 }
32
33 $argv = $args->getArg('argv');
34 if (!$argv) {
35 throw new PhutilArgumentUsageException(
36 pht(
37 'Specify a command to run.'));
38 }
39
40 $lease = id(new DrydockLeaseQuery())
41 ->setViewer($this->getViewer())
42 ->withIDs(array($lease_id))
43 ->executeOne();
44 if (!$lease) {
45 throw new Exception(
46 pht(
47 'Unable to load lease with ID "%s"!',
48 $lease_id));
49 }
50
51 // TODO: Check lease state, etc.
52
53 $interface = $lease->getInterface(DrydockCommandInterface::INTERFACE_TYPE);
54
55 list($stdout, $stderr) = call_user_func_array(
56 array($interface, 'execx'),
57 array('%Ls', $argv));
58
59 fwrite(STDOUT, $stdout);
60 fwrite(STDERR, $stderr);
61
62 return 0;
63 }
64
65}