繁体   English   中英

CLI中通配符路由的不良行为

[英]Undesired behaviour of wildcard routes in CLI

我的CLI应用程序中包含以下路由:

system
system *
system info
system info *
system settings
system settings *
system tunables
system tunables *
system logging
system logging *
system logging settings
system logging settings *

并想要这样的行为:

  • 如果输入system命令-> exec system处理程序
  • 如果输入了system ANYTHING_BUT_CONFIGURED_ROUTES命令-> exec system *处理程序,则除了ANYTHING_BUT_CONFIGURED_ROUTES什么都没有:

    信息设置可调参数记录

问题与app.cmd()执行顺序有关:

  • 如果我以相反的顺序注册路由,则处理程序将正确执行

  • 如果我以与上述顺序相同的顺序注册路由,则如果我执行system info ,则会触发system *的处理程序,而不是system info

关于如何克服这一点的任何建议?

我目前正在通过循环和构造一个逆数组然后再次循环来解决此问题,但是对于一个简单的CLI应用程序来说,这会花费很多时间,而且很麻烦,因此我正在寻找其他解决方案。

不知道您使用的模块,这个问题很有意义,它是在首次发现时就匹配的,不是最具体的...但是您不必完全重新排列列表,只需将通配符放在特定条目之后,就像这样:

system
system info
system info *
system settings
system settings *
system tunables
system tunables *
system logging
system logging settings
system logging settings *
system logging *
system *

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM