Search code examples
pythonargparseappimage

How to override the cli name in argparse -h usage information?


I am bundling my python app into an .AppImage file. Now, when I run it with flag -h I would expect it to print something along these lines:

$ ./mytool.AppImage -h
usage: mytool [-h] [-d DIR] [-f] [-e] [BLA [BLA ...]]
...

But due to the nature of the AppImage bundling process I get:

$ ./mytool.AppImage -h
usage: AppRun [-h] [-d DIR] [-f] [-e] [BLA [BLA ...]]
...

That is, AppRun instead of mytool.

So my question is:

How can I force override the app name so that regardless of how the app is called it will always print the same name in the usage string?


Solution

  • As per hpaulj's comment, this can solved by simply setting the prog parameter of the argparse.ArgumentParser constructor:

    parser = argparse.ArgumentParser(
            prog='mytool',
            description='Some description...'
    )