summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPyHedgehog <pyhedgehog@users.noreply.github.com>2023-03-11 13:10:42 +0300
committerGitHub <noreply@github.com>2023-03-11 10:10:42 +0000
commit4f7c78436e62bfd21745c5289117e03ed896bc66 (patch)
treec62e51cf93a6770d9b876107a4ad41dc927c065f
parent7d779c85ffe09623c5d885b5a429b0242ad82f93 (diff)
downloadgitlab-4f7c78436e62bfd21745c5289117e03ed896bc66.tar.gz
fix(cli): add ability to escape at-prefixed parameter (#2513)
* fix(cli): Add ability to escape at-prefixed parameter (#2511) --------- Co-authored-by: Nejc Habjan <hab.nejc@gmail.com>
-rw-r--r--docs/cli-usage.rst11
-rw-r--r--gitlab/cli.py2
-rw-r--r--tests/functional/cli/test_cli_v4.py20
3 files changed, 33 insertions, 0 deletions
diff --git a/docs/cli-usage.rst b/docs/cli-usage.rst
index c728221..4b525fc 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 an argument starting with ``@``, you can escape it using ``@@``:
+
+.. 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 c124e74..4efb3b2 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 921aa78..684293f 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"