dpb_4431 2019-09-02 07:36
浏览 87
已采纳

有没有一种方法可以使用Go的`flag`包捕获所有无法识别的命令行标志?

I'm currently writing a wrapper around git diff, and it would be nice if any flag that wasn't immediately relevant to my program would be passed through to git diff. So for example:

  • Running my-tool eventually runs git diff
  • Running my-tool --dir eventually runs git diff --dir

I'm using the flag package for parsing command line flags, however, and it looks like there's no option to collect unrecognised flags. I've also investigated the pflag package, which has the ability to keep running when encountering an unknown flag, but doesn't appear to offer a way to collect these unrecognised flags.

My question is -- is there a way of parsing flags that also allows collection of unrecognised flags, short of copying one of these implementations and modifying it?

  • 写回答

1条回答 默认 最新

  • dqaq59269 2019-09-02 07:48
    关注

    [I]s there a way of parsing flags that also allows collection of unrecognised flags, short of copying one of these implementations and modifying it?

    No.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 人在外地出差,速帮一点点
  • ¥15 如何使用canvas在图片上进行如下的标注,以下代码不起作用,如何修改
  • ¥15 Windows 系统cmd后提示“加载用户设置时遇到错误”
  • ¥50 vue router 动态路由问题
  • ¥15 关于#.net#的问题:End Function
  • ¥15 无法import pycausal
  • ¥15 VS2022创建MVC framework提示:预安装的程序包具有对缺少的注册表值的引用
  • ¥15 weditor无法连接模拟器Local server not started, start with?
  • ¥20 6-3 String类定义
  • ¥15 嵌入式--定时器使用