From c5496870e55246f507994d63d4dc7a5e91e67fcc Mon Sep 17 00:00:00 2001 From: Ruslan Kuprieiev Date: Mon, 14 Dec 2020 12:25:46 +0200 Subject: [PATCH] cli: config: check name format (#5090) MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Currently we don't handle bad name well: ``` (dvc-3.8.3) ➜ dvc git:(config-bug) ✗ dvc config section ERROR: unexpected error - not enough values to unpack (expected 2, got 1) ``` With this PR, we check name to conform to either `remote.name.option` or `section.option`, so we'll give a more friendly: ``` (dvc-3.8.3) ➜ dvc git:(config-bug) ✗ dvc config section ERROR: argument name: name argument should look like remote.name.option or section.option usage: dvc config [-h] [--global | --system | --local] [-q | -v] [-u] [-l] [name] [value] Get or set config options. Documentation: positional arguments: name Option name (remote.name.option or section.option). value Option value. optional arguments: -h, --help show this help message and exit --global Use global config. --system Use system config. --local Use local config. -q, --quiet Be quiet. -v, --verbose Be verbose. -u, --unset Unset option. -l, --list List all defined config values. ``` --- dvc/command/config.py | 49 ++++++++++++++++++++++++------- tests/func/test_cli.py | 4 +-- tests/func/test_config.py | 16 ++++++++++ tests/unit/command/test_config.py | 11 +++++++ 4 files changed, 68 insertions(+), 12 deletions(-) diff --git a/dvc/command/config.py b/dvc/command/config.py index ab2ecafdf..d615aa742 100644 --- a/dvc/command/config.py +++ b/dvc/command/config.py @@ -7,6 +7,25 @@ from dvc.utils.flatten import flatten logger = logging.getLogger(__name__) +NAME_REGEX = r"^(?Premote\.)?(?P
[^\.]*)\.(?P