设置自动日志,任何时间单击CLI命令?
我当前在代码中使用单击
来设置大量命令行工具,但是我想运行相当于click.echo(“ Cli Function X”)任何时间函数
x
被调用。有没有办法在我的项目中进行一般设置?还是我必须为每个CLI功能分别添加此功能?
I currently use click
inside my code for setting up plenty of command line tools, but I'd like to run the equivalent of click.echo("CLI function X was called")
any time function X
is called. Is there a way to set up this up generally across my project? Or do I have to add this function individually for each CLI function?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我需要这个并修改这个答案以获取解决方案。给定此基本单击组:
我添加了一个函数,该函数采用上下文并调用方法:
然后,我创建了一些自定义类,覆盖
Invoke
命令以调用上述函数:将功能添加到现有脚本中很简单,将类通过
cls
参数将类传递到装饰符中,即:运行
Hello
命令现在在命令执行之前和之后打印到控制台:I needed this and modified this answer to get a solution. Given this basic click group:
I added a function that takes a context and invoke method:
I then created a few custom classes that override the
invoke
command to call the above function:Adding the functions to the existing script is simple, pass the classes into the decorators for the groups and methods with the
cls
argument, i.e.:Running the
hello
command now prints to the console before and after the command's execution: