1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-25 16:22:43 +01:00

In "bin/drydock lease", take a JSON "--attributes" so we can accept complex values

Summary:
Depends on D19750. See T13210. The `bin/drydock lease` command makes it easier to request ad-hoc leases, but currently takes lease attributes in the form `--attributes x=y,a=b`.

This was okay for all leases at the time, but doesn't really work for modern WorkingCopy resources since they take a `repositories.map` which has a dictionary as a value. You can't specify that with `repositories.map=...`.

Instead, point `--attributes` at a JSON file or use `--attributes -` to read from stdin.

Test Plan: Used `--attributes` with a file and stdin to allocate working copy leases with repositories.

Reviewers: amckinley

Reviewed By: amckinley

Subscribers: PHID-OPKG-gm6ozazyms6q6i22gyam

Differential Revision: https://secure.phabricator.com/D19751
This commit is contained in:
epriestley 2018-10-23 17:39:47 -07:00
parent 6deb09efcd
commit 1f6869a765

View file

@ -20,9 +20,11 @@ final class DrydockManagementLeaseWorkflow
'help' => pht('Set lease expiration time.'),
),
array(
'name' => 'attributes',
'param' => 'name=value,...',
'help' => pht('Resource specification.'),
'name' => 'attributes',
'param' => 'file',
'help' => pht(
'JSON file with lease attributes. Use "-" to read attributes '.
'from stdin.'),
),
));
}
@ -49,11 +51,20 @@ final class DrydockManagementLeaseWorkflow
}
}
$attributes = $args->getArg('attributes');
if ($attributes) {
$options = new PhutilSimpleOptions();
$options->setCaseSensitive(true);
$attributes = $options->parse($attributes);
$attributes_file = $args->getArg('attributes');
if (strlen($attributes_file)) {
if ($attributes_file == '-') {
echo tsprintf(
"%s\n",
'Reading JSON attributes from stdin...');
$data = file_get_contents('php://stdin');
} else {
$data = Filesystem::readFile($attributes_file);
}
$attributes = phutil_json_decode($data);
} else {
$attributes = array();
}
$lease = id(new DrydockLease())