Skip to content

Commit

Permalink
fix(cli): Add ability to escape at-prefixed parameter (python-gitlab#…
Browse files Browse the repository at this point in the history
  • Loading branch information
pyhedgehog committed Mar 9, 2023
1 parent 7d779c8 commit 1774415
Show file tree
Hide file tree
Showing 3 changed files with 33 additions and 0 deletions.
11 changes: 11 additions & 0 deletions docs/cli-usage.rst
Original file line number Diff line number Diff line change
Expand Up @@ -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
=============================

Expand Down
2 changes: 2 additions & 0 deletions gitlab/cli.py
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
20 changes: 20 additions & 0 deletions tests/functional/cli/test_cli_v4.py
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down

0 comments on commit 1774415

Please sign in to comment.