1

I've been using click module for some time now and I think it's awesome. However I have some problems using it in a WinDbg python plugin.

I'm using the following script, which works fine in Linux:

import click

@click.group()
def shell():
    pass

@shell.command()
@click.option('--name', help='Your name please')
def hello(name):
    click.echo(name)

if __name__ == "__main__":
    shell()

A successful invocation of a script can be seen below (this is in Linux command line):

# python test.py hello --name=aaa
aaa

An unsuccessful invocation of a script can be seen below (this is in WinDbg plugin):

0:000> !py C:\Users\windbg\test.py hello --name=aaa
Usage: test.py [OPTIONS] COMMAND [ARGS]...

Options:
  --help  Show this message and exit.

Commands:
  hello

Any ideas why this happens and why a WinDbg plugin doesn't accept parameters in order for them to be parsed by click correctly.

Thomas Weller
  • 55,411
  • 20
  • 125
  • 222
eleanor
  • 1,514
  • 3
  • 19
  • 40
  • PyKd [supports regular arguments](https://pykd.codeplex.com/wikipage?title=PYKD%200.2.%20Documentation&referringTitle=Documentation#windbgcommands-runningscripts). Can you check whether that works? When was that annotation/decoration syntax available in Python? Could it be a Python 2/3 version issue? – Thomas Weller Jan 28 '16 at 19:31

1 Answers1

3

It is click "feature":

see click\utils.py:

if PY2 and WIN and _initial_argv_hash == _hash_py_argv():
    return _get_windows_argv() 
return sys.argv[1:]

def _get_windows_argv():
    argc = c_int(0)
    argv_unicode = CommandLineToArgvW(GetCommandLineW(), byref(argc)) 

So, click gets args not from sys.args, but from windbg real commandline.

You can easy fix this:

if __name__ == "__main__":
    import sys
    shell(args=sys.argv[1:])
ussrhero
  • 161
  • 1
  • 3