Skip to content

fix(cli): add ability to escape at-prefixed parameter #2513

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Mar 11, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 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
=============================

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