Closed varioustoxins closed 1 year ago
This is your shell, not something click can control. You need to properly quote tokens containing spaces and dashes. You've also provided an example using typer, not click.
The following example works for me:
import click
@click.command
@click.argument("name", type=click.Path())
def main(name):
click.echo(name)
main()
$ python example.py 'a - b'
a - b
So this problem happens with typer rather than click directly, but its definitely not a shell problem as the path works with cat and grep but not a python program with the same arguments. I will try and refine the problem into a more clear example
tried your code on my machine and it seems fine, I presume its something to do with typer
when I have a command that takes a path if I use a path containing a dash surrounded by escapes it is interpreted as an option
e.g.
@nef_app.app.command() def stream( file_name: Path = typer.Argument(..., help='input file') ):
app ${HOME}/OneDrive\ -\ University\ of\ Kent/file.txt
Error: No such option: -\ inputs: stream /Users/garythompson/OneDrive\ -\ University\ of\ Kent/file.txt exiting...
adding quotes doesn't improve things...
app ${HOME}/'OneDrive - University of Kent/file.txt'
Error: Got unexpected extra arguments (- University of Kent/file.txt) inputs: stream ${HOME}/OneDrive - University of Kent/file.txt exiting...
click should be able to correctly deal with filenames that contain dashes and escaped spaces
for example cat is quite happy to stream the same file and grep can grep the contents
Environment:
Python version: 3.10.0 (default, Oct 27 2021, 09:04:48) [Clang 12.0.0 (clang-1200.0.32.29)] Operating system: macOS-10.15.7-x86_64-i386-64bit Click version: 8.1.3