问题描述
我有以下用于 CLI A (see the real repository) 的命令:
$ cli-a -h
Usage:
cli-a [command]
Available Commands:
command-a1 command description
command-a2 command description
command-a3 command description
Flags:
--config string config file (default is $HOME/.cli-a.json)
-h,--help help for cli-a
Use "cli-a [command] --help" for more information about a command.
而且,对于 CLI B,我有以下命令 (see the real repository):
$ cli-b -h
Usage:
cli-b [command]
Available Commands:
command-b1 command description
command-b2 command description
command-b3 command description
Flags:
--kubeconfig string path to kubeconfig file
-h,--help help for cli-b
Use "cli-b [command] --help" for more information about a command.
我现在想要做的是,我希望 CLI B(及其所有子命令)成为 CLI A 的子命令,如下所示:
$ cli-a -h
Usage:
cli-a [command]
Available Commands:
command-a1 command description
command-a2 command description
command-a3 command description
cli-b description about cli-b
Flags:
--config string config file (default is $HOME/.cli-a.json)
-h,--help help for cli-a
Use "cli-a [command] --help" for more information about a command.
所以当用户运行 $ cli-a cli-b -h
时,他们会看到:
$ cli-a cli-b -h
Usage:
cli-a cli-b [command]
Available Commands:
command-b1 command description
command-b2 command description
command-b3 command description
Flags:
--kubeconfig string path to kubeconfig file
-h,--help help for cli-b
Use "cli-a cli-b [command] --help" for more information about a command.
两个 repos 位于不同的 Go 模块名称/存储库中。如果用户不喜欢下载和使用 CLI A 中的所有功能,我仍然想向他们提供 CLI B 下载。
CLI B 的大部分工作(功能、错误修复等)将在 CLI B 存储库中完成,我正在考虑在我的 CLI A 的 CI 管道中组合/合并它们两个(需要考虑如何做这也是)。
如果可能,我不想在每次更改 CLI B 代码库(业务逻辑、CLI 标志等)时更改/更新 CLI A 代码库中的任何内容。我希望 CLI A 就像 CLI B 的代理服务器一样(我在这里使用一个类比) - 所有业务逻辑都保存在 CLI B 代码库中。
而且,如果您仔细查看上面的示例输出,当用户运行 $ cli-a cli-b -h
或 $ cli-a cli-b command-bN [-h]
时,我不希望 CLI A 的根标志 (--config
) 出现并采取影响。相反,我希望 CLI B 的根标志 (--kubeconfig
) 出现并生效。
问题
- 这对 Cobra 是否可行?
- 在不向 CLI A 的存储库中添加太多代码的情况下实现这一目标的最佳方法是什么?
- 项目结构/树应该是什么样子的?
- 有什么好的例子可以参考吗?
- 在高层次上,我应该在 CLI A 的构建/CI 管道中做什么来实现这一目标?
我非常感谢这里的所有输入、指针、示例和外部资源。提前致谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)