How to run command after initialisation #1415
-
I know I can do commands at invocation based on https://cmd2.readthedocs.io/en/2.5.9/features/startup_commands/#commands-at-invocation However, I need to use argparse before starting the CLI, so I will need to do My current workaround is to append the commands to the What do you think is the best way to implement such a feature? |
Beta Was this translation helpful? Give feedback.
Replies: 1 comment
-
I've done exactly this in my cmd2 based app. Here's the code: https://github.com/tomcatmanager/tomcatmanager/blob/main/src/tomcatmanager/__main__.py#L174 My version doesn't allow multiple commands, but you could easily add that by checking the return value of the |
Beta Was this translation helpful? Give feedback.
I've done exactly this in my cmd2 based app. Here's the code: https://github.com/tomcatmanager/tomcatmanager/blob/main/src/tomcatmanager/__main__.py#L174
My version doesn't allow multiple commands, but you could easily add that by checking the return value of the
onecmd_plus_hooks()
call. If true, you shouldn't run subsequent commands.