microsoft / knack

Knack - A Python command line interface framework
https://pypi.python.org/pypi/knack
MIT License
348 stars 95 forks source link

[Event] Add EVENT_CLI_SUCCESSFUL_EXECUTE #224

Closed jiasli closed 3 years ago

jiasli commented 3 years ago

Context

In the current implementation, the command handler is invoked at L215:

https://github.com/microsoft/knack/blob/0d0308bc567f2d25654bb39201c02ab262d7ce0a/knack/cli.py#L215

The JSON is printed at L221:

https://github.com/microsoft/knack/blob/8b3757ddff6b63bf4789c8736a506e1754f1f92b/knack/cli.py#L221

Therefore, anything printed by the command handler will be shown before the JSON output.

Change

Add a new event EVENT_CLI_SUCCESSFUL_EXECUTE. It is raised after a command is successfully executed, allowing a callback func to be registered and called after JSON is printed.

This enables post-output hint to be displayed after the JSON output.