Comma treated as special by parse_commandline, but not by shell_quote

Issue #34 resolved
Former user created an issue

sarge.parse_command_line(sarge.shell_format("ls {0}", "foo,bar")) results in CommandNode(command=['ls', 'foo', ',', 'bar'] redirects={})

which causes

sarge.run("ls foo,bar")
ls: cannot access foo: No such file or directory
ls: cannot access ,: No such file or directory
ls: cannot access bar: No such file or directory

Whereas my shell does the following:

ls foo,bar
ls: cannot access foo,bar: No such file or directory

I initially found this issue when trying to run commands with comma-separated options:

sarge.run(foo --output-format=txt,json,xml)

which would cause it to run foo --output-format=txt foo bar

Comments (2)

  1. Vinay Sajip repo owner

    Note that this is how shlex.shlex parses that command-line:

    >>> import shlex
    >>> cmd = 'ls foo,bar'
    >>> list(shlex.shlex(cmd, posix=True))
    ['ls', 'foo', ',', 'bar']
    >>> list(shlex.shlex(cmd, posix=False))
    ['ls', 'foo', ',', 'bar']
    

    The tokenisation done by sarge uses asubclass of shlex.shlex, which is why it parses the same way.

  2. Log in to comment