Pattern-based commands and specific actions for empty commands #1246
-
I'm writing an application that I use to track my working hours on various projects, and I'm trying to decide if using The principle behind my time tracking application is minimum amount of keystrokes to enter data. Thus if I want to log an activity, any command that starts with a float logs that many hours. Optional arguments can follow that and are parsed accordingly. For example, a command such as Having optional arguments in Another feature of this application is that it reads my Outlook calendar, and prompts me to make time entries based on that. For example, if I have a 1 hour team meeting on my outlook calendar, the application will prompt me as to whether that was correct. If it was, I simply press Is there a way to use an empty command to do something specific, based on the state of the program? I've implemented all of the above with my own console module in my project called titr. It works, but the console is rough around the edges, and doesn't have some of the nicer features of Looking forward to hearing any thoughts and feedback. |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments
-
This behavior is very different from how most of cmd behaves. There are 2 avenues you could explore, though. In the Completion starts by calling the As for the note about decorators vs |
Beta Was this translation helpful? Give feedback.
-
Thanks, this pointed me in the right direction. I was able to get the pattern-based behavior by modifying |
Beta Was this translation helpful? Give feedback.
This behavior is very different from how most of cmd behaves. There are 2 avenues you could explore, though.
In the
Cmd
class, all commands eventually hit theonecmd()
function where it attempts to locate thedo_
function that corresponds to a command. If it can't find a command, it calls thedefault()
function. You could try overridingdefault()
and, failing that, try overridingonecmd()
. If you have custom state tracking, you can probably use as the basis for determining which of your functions you want to call.Completion starts by calling the
Cmd.complete()
function which then looks up the command function and determines the type of completion depending on the specifics of the command…