From 1f6869a7654a8215ddf9afc8567fa6b44cae364b Mon Sep 17 00:00:00 2001 From: epriestley Date: Tue, 23 Oct 2018 17:39:47 -0700 Subject: [PATCH] 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 --- .../DrydockManagementLeaseWorkflow.php | 27 +++++++++++++------ 1 file changed, 19 insertions(+), 8 deletions(-) diff --git a/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php b/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php index 75636dab09..7371232620 100644 --- a/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php +++ b/src/applications/drydock/management/DrydockManagementLeaseWorkflow.php @@ -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())