From 66e4955408eacb4859cfef01a31d013e34c28ffb Mon Sep 17 00:00:00 2001 From: Jens Harbott Date: Wed, 6 Dec 2017 09:32:29 +0000 Subject: [PATCH] Improve recordset create UI The current implementation has '--records' as a quasi-positional argument, with the nargs='+' parameter it can only be used at the end of the command, which is confusing to users and doesn't comply with the help message. Add a new option '--record' that takes only exactly one record as parameter and can be repeated when multiple records are present. Deprecate the old option so it can be removed in the future. Change-Id: I8fefd9d0f104170d50c5d5dc3cbcc53facda9baf Closes-Bug: 1736161 --- designateclient/v2/cli/recordsets.py | 20 +++++++++++++++++--- 1 file changed, 17 insertions(+), 3 deletions(-) diff --git a/designateclient/v2/cli/recordsets.py b/designateclient/v2/cli/recordsets.py index 9abe611..898da19 100644 --- a/designateclient/v2/cli/recordsets.py +++ b/designateclient/v2/cli/recordsets.py @@ -14,6 +14,7 @@ # License for the specific language governing permissions and limitations # under the License. +import argparse import logging from osc_lib.command import command @@ -140,13 +141,22 @@ class ShowRecordSetCommand(command.ShowOne): class CreateRecordSetCommand(command.ShowOne): """Create new recordset""" + log = logging.getLogger('deprecated') + def get_parser(self, prog_name): parser = super(CreateRecordSetCommand, self).get_parser(prog_name) parser.add_argument('zone_id', help="Zone ID") parser.add_argument('name', help="RecordSet Name") - parser.add_argument('--records', help="RecordSet Records", - nargs='+', required=True) + req_group = parser.add_mutually_exclusive_group(required=True) + req_group.add_argument( + '--records', + help=argparse.SUPPRESS, + nargs='+') + req_group.add_argument( + '--record', + help="RecordSet Record, repeat if necessary", + action='append') parser.add_argument('--type', help="RecordSet Type", required=True) parser.add_argument('--ttl', type=int, help="Time To Live (Seconds)") parser.add_argument('--description', help="Description") @@ -159,11 +169,15 @@ class CreateRecordSetCommand(command.ShowOne): client = self.app.client_manager.dns common.set_all_common_headers(client, parsed_args) + all_records = parsed_args.record or parsed_args.records + if parsed_args.records: + self.log.warning( + "Option --records is deprecated, use --record instead.") data = client.recordsets.create( parsed_args.zone_id, parsed_args.name, parsed_args.type, - parsed_args.records, + all_records, description=parsed_args.description, ttl=parsed_args.ttl)