Skip to content

Commit 4f7c784

Browse files
pyhedgehognejch
andauthored
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>
1 parent 7d779c8 commit 4f7c784

File tree

3 files changed

+33
-0
lines changed

3 files changed

+33
-0
lines changed

docs/cli-usage.rst

+11
Original file line numberDiff line numberDiff line change
@@ -305,6 +305,17 @@ command line. This is handy for values containing new lines for instance:
305305
EOF
306306
$ gitlab project create --name SuperProject --description @/tmp/description
307307
308+
It you want to explicitly pass an argument starting with ``@``, you can escape it using ``@@``:
309+
310+
.. code-block:: console
311+
312+
$ gitlab project-tag list --project-id somenamespace/myproject
313+
...
314+
name: @at-started-tag
315+
...
316+
$ gitlab project-tag delete --project-id somenamespace/myproject --name '@@at-started-tag'
317+
318+
308319
Enabling shell autocompletion
309320
=============================
310321

gitlab/cli.py

+2
Original file line numberDiff line numberDiff line change
@@ -272,6 +272,8 @@ def _get_parser() -> argparse.ArgumentParser:
272272

273273

274274
def _parse_value(v: Any) -> Any:
275+
if isinstance(v, str) and v.startswith("@@"):
276+
return v[1:]
275277
if isinstance(v, str) and v.startswith("@"):
276278
# If the user-provided value starts with @, we try to read the file
277279
# path provided after @ as the real value. Exit on any error.

tests/functional/cli/test_cli_v4.py

+20
Original file line numberDiff line numberDiff line change
@@ -562,6 +562,26 @@ def test_create_project_with_values_from_file(gitlab_cli, tmpdir):
562562
assert description in ret.stdout
563563

564564

565+
def test_create_project_with_values_at_prefixed(gitlab_cli, tmpdir):
566+
name = "gitlab-project-at-prefixed"
567+
description = "@at-prefixed"
568+
at_prefixed = f"@{description}"
569+
570+
cmd = [
571+
"-v",
572+
"project",
573+
"create",
574+
"--name",
575+
name,
576+
"--description",
577+
at_prefixed,
578+
]
579+
ret = gitlab_cli(cmd)
580+
581+
assert ret.success
582+
assert description in ret.stdout
583+
584+
565585
def test_create_project_deploy_token(gitlab_cli, project):
566586
name = "project-token"
567587
username = "root"

0 commit comments

Comments
 (0)