OiO.lk Community platform!

Oio.lk is an excellent forum for developers, providing a wide range of resources, discussions, and support for those in the developer community. Join oio.lk today to connect with like-minded professionals, share insights, and stay updated on the latest trends and technologies in the development field.
  You need to log in or register to access the solved answers to this problem.
  • You have reached the maximum number of guest views allowed
  • Please register below to remove this limitation

How to use windows_expand_args with single command click program

  • Thread starter Thread starter Brad Campbell
  • Start date Start date
B

Brad Campbell

Guest
I'm trying to defeat click 8.x's behavior on windows of expanding glob patterns on Windows by default. This seems straightforward for a multi-command where you define group. But I can't figure out how to do it for a single command program. Take the following example saved as mycommand.py:

Code:
import click

@click.command("mycommand")
@click.argument("filepattern", nargs=1, type=str)
def mycommand(filepattern):
    print(filepattern)


if __name__ == "__main__":
    mycommand()

If I have a directory full of, say Python files, if I invoke this as python mycommand.py somefile.py, it will succeed as one value gets passed into filepattern and it will echo somefile.py.

If I invoke as python mycommand.py *.py it fails with an error like:

Code:
Usage: mycommand.py [OPTIONS] FILEPATTERN
Try 'mycommand.py --help' for help.

Error: Got unexpected extra arguments (scratch.py mycommand.py ...)

I know there is an argument windows_expand_args for a click.group, but I can't puzzle out how to get it to work for a single command program.
<p>I'm trying to defeat click 8.x's behavior on windows of expanding glob patterns on Windows by default. This seems straightforward for a multi-command where you define group. But I can't figure out how to do it for a single command program. Take the following example saved as <code>mycommand.py</code>:</p>
<pre><code>import click

@click.command("mycommand")
@click.argument("filepattern", nargs=1, type=str)
def mycommand(filepattern):
print(filepattern)


if __name__ == "__main__":
mycommand()
</code></pre>
<p>If I have a directory full of, say Python files, if I invoke this as <code>python mycommand.py somefile.py</code>, it will succeed as one value gets passed into <code>filepattern</code> and it will echo <code>somefile.py</code>.</p>
<p>If I invoke as <code>python mycommand.py *.py</code> it fails with an error like:</p>
<pre><code>Usage: mycommand.py [OPTIONS] FILEPATTERN
Try 'mycommand.py --help' for help.

Error: Got unexpected extra arguments (scratch.py mycommand.py ...)
</code></pre>
<p>I know there is an argument <code>windows_expand_args</code> for a <code>click.group</code>, but I can't puzzle out how to get it to work for a single command program.</p>
 

Latest posts

I
Replies
0
Views
1
impact christian
I
Top