1

I am searching for a way to implement master commands for my python script. By master commands i mean one command summarizing a sequence of commands.

An example call with all commands written out:

python script.py -import model.glb -remove_small_features -decimate -bake_textures -export lowpoly.glb

An example call with the master command which leads to the same result:

python script.py -import model.glb -compact -export lowpoly.glb

Currently i am using in my python code something like:

if arguments.compact:
    arguments.remove_small_features = True
    arguments.decimate = True
    arguments.bake_textures = True

But is there a way to represent this structure in the argparse module itself? I haven't found a way to do this. I found mutually exclusive groups which allows for parsing that certain arguments are not allowed to be together in one call but not that one argument sets the values multiple another arguments.

Mamu
  • 21
  • 2
  • No, this does not exist, however you may wish to implement a custom [`Action`](https://docs.python.org/3/library/argparse.html#action-classes) that will let you associate with a flag, where if that flag is set (i.e. `-compact`, it will set the associated flags. This `Action` may be produced by a factory function that will take in the specific flags that will be applied, and then call `store_const` for those flags. This will naturally involve more work so I don't know if that's worth your while, though you will gain more readability and reusability out of that. – metatoaster Jul 28 '20 at 09:10

0 Answers0