Skip to content

cli: Can't escape initial at (@) in parameter #2511

Closed

Description

@pyhedgehog

Description

Symbol "@" in all parameter values parsed as file reference, and I found no way to override this behaviour.

python-gitlab/gitlab/cli.py

Lines 274 to 285 in 9c24657

def _parse_value(v: Any) -> Any:
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.
try:
with open(v[1:], encoding="utf-8") as f:
return f.read()
except Exception as e:
sys.stderr.write(f"{e}\n")
sys.exit(1)
return v

Expected Behavior

gitlab project-tag delete --project-id somenamespace/myproject --name '@at-started-tag'

Command executed without errors and tag is deleted.

Actual Behavior

$ gitlab project-tag delete --project-id somenamespace/myproject --name '@at-started-tag'
[Errno 2] No such file or directory: 'at-started-tag'

Activity

  1. changed the title [-]Can't escape initial at (@) in parameter[/-] [+]cli: Can't escape initial at (@) in parameter[/+] on Mar 6, 2023
  2. JohnVillalovos commented on Mar 7, 2023

    @JohnVillalovos
    Member

    Yes that does seem like a use-case not considered before. I'm not sure the best way to fix that.

    My initial thought would be to be able to do: \@at-started-tag and the code could check for content starting with \@ and if so return back the value without the backslash.

    @nejch Do you have any ideas?

  3. pyhedgehog commented on Mar 9, 2023

    @pyhedgehog
    ContributorAuthor

    @JohnVillalovos as soon as this is place-specific escape (i.e. it should not be replaced anywhere else except string start) I'd prefer @@.

  4. nejch commented on Mar 10, 2023

    @nejch
    Member

    A bit late to the party here sorry folks! :) @JohnVillalovos @pyhedgehog I like the idea with an escape character and \ is more standard. Although @@ does look a bit more pleasing visually and is consistent with GitLab's double-escaping dollar signs in variables (https://docs.gitlab.com/ee/ci/variables/#use-the--character-in-cicd-variables). So maybe we could go with that.

  5. pyhedgehog commented on Mar 10, 2023

    @pyhedgehog
    ContributorAuthor

    @nejch It's in line with $$ in gitlab CICD, docker-compose.yml, and '' in SQL strings. :-)
    If you like this, you can just approve my PR. If you prefer backslash tell me, i'll change my PR.

  6. JohnVillalovos commented on Mar 10, 2023

    @JohnVillalovos
    Member

    I'm perfectly fine with @@

  7. locked as resolved and limited conversation to collaborators on Mar 11, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions