From 17744151d9b152e4a4fc5958409e4fbd995c98c1 Mon Sep 17 00:00:00 2001 From: Michael Dubner Date: Thu, 9 Mar 2023 20:35:11 +0300 Subject: [PATCH 1/2] fix(cli): Add ability to escape at-prefixed parameter (#2511) --- docs/cli-usage.rst | 11 +++++++++++ gitlab/cli.py | 2 ++ tests/functional/cli/test_cli_v4.py | 20 ++++++++++++++++++++ 3 files changed, 33 insertions(+) diff --git a/docs/cli-usage.rst b/docs/cli-usage.rst index c7282217c..3b67e6f83 100644 --- a/docs/cli-usage.rst +++ b/docs/cli-usage.rst @@ -305,6 +305,17 @@ command line. This is handy for values containing new lines for instance: EOF $ gitlab project create --name SuperProject --description @/tmp/description +It you want to explicitly pass argument starting with "@" - double it: + +.. code-block:: console + + $ gitlab project-tag list --project-id somenamespace/myproject + ... + name: @at-started-tag + ... + $ gitlab project-tag delete --project-id somenamespace/myproject --name '@@at-started-tag' + + Enabling shell autocompletion ============================= diff --git a/gitlab/cli.py b/gitlab/cli.py index c124e7498..4efb3b2ff 100644 --- a/gitlab/cli.py +++ b/gitlab/cli.py @@ -272,6 +272,8 @@ def _get_parser() -> argparse.ArgumentParser: def _parse_value(v: Any) -> Any: + if isinstance(v, str) and v.startswith("@@"): + return v[1:] if isinstance(v, str) and v.startswith("@"): # If the user-provided value starts with @, we try to read the file # path provided after @ as the real value. Exit on any error. diff --git a/tests/functional/cli/test_cli_v4.py b/tests/functional/cli/test_cli_v4.py index 921aa78b2..684293f30 100644 --- a/tests/functional/cli/test_cli_v4.py +++ b/tests/functional/cli/test_cli_v4.py @@ -562,6 +562,26 @@ def test_create_project_with_values_from_file(gitlab_cli, tmpdir): assert description in ret.stdout +def test_create_project_with_values_at_prefixed(gitlab_cli, tmpdir): + name = "gitlab-project-at-prefixed" + description = "@at-prefixed" + at_prefixed = f"@{description}" + + cmd = [ + "-v", + "project", + "create", + "--name", + name, + "--description", + at_prefixed, + ] + ret = gitlab_cli(cmd) + + assert ret.success + assert description in ret.stdout + + def test_create_project_deploy_token(gitlab_cli, project): name = "project-token" username = "root" From 060b2a82706ec0289aabf92df43d3f079877c336 Mon Sep 17 00:00:00 2001 From: Nejc Habjan Date: Sat, 11 Mar 2023 10:59:28 +0100 Subject: [PATCH 2/2] chore: apply review suggestion --- docs/cli-usage.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/docs/cli-usage.rst b/docs/cli-usage.rst index 3b67e6f83..4b525fc5d 100644 --- a/docs/cli-usage.rst +++ b/docs/cli-usage.rst @@ -305,7 +305,7 @@ command line. This is handy for values containing new lines for instance: EOF $ gitlab project create --name SuperProject --description @/tmp/description -It you want to explicitly pass argument starting with "@" - double it: +It you want to explicitly pass an argument starting with ``@``, you can escape it using ``@@``: .. code-block:: console