<p>This is what I've found for now:</p>
<ul>
<li>urfave/cli is a new name for codegangsta/cli</li>
<li>spf13/cobra works on top of sp13/pflag (GNU-style flags) which is a fork of ogier/pflag</li>
<li>you can use spf13/viper (12-factor apps) which works on top of spf13/cobra</li>
<li>urfave/cli used in docker/libcompose, docker/machine, drone, gogs</li>
<li>spf13/cobra used in docker/docker, docker/distribution, etcd, rkt</li>
<li>some projects are moved from stdlib's flag to urfave/cli</li>
<li>some projects are moved from urfave/cli to spf13/cobra</li>
</ul>
<p><strong>UPDATE 2017-02-07</strong>:</p>
<p>Seems like the original author of codegangsta/cli votes for spf13/cobra package.</p>
<p>Cobra: A Modern & Refined CLI Commander - <a href="https://blog.gopheracademy.com/advent-2014/introducing-cobra/">https://blog.gopheracademy.com/advent-2014/introducing-cobra/</a></p>
<blockquote>
<p>"Cobra is a really clean package. I wish my own CLI library was as good!" - Jeremy Saenz (author of codegangsta/cli)</p>
</blockquote>
<hr/>**评论:**<br/><br/>lluad: <pre><p>I switched from cli to cobra, after a couple of months of dealing with some minor annoyances in cli (one of which - inability to return errors from subcommands - has since been fixed in HEAD).</p>
<p>It took very little time to port from one to the other. They're similar in style, though cli is a bit more of an opinionated framework while cobra is marginally more of a toolbox.</p>
<p>They're both pretty good. Having now used both, for the same target app, I'm probably going to stick with cobra in the future.</p></pre>titpetric: <pre><p>Well, I can't say for sure but it seems that spf13 is more widely adopted, most likely not because of some technical difference, but as a measure of respect & popularity. When choosing between two different packages that might do almost the same thing, a factor what to choose is <em>who</em> makes it (spf13 has direct affiliation with google and golang, judging from his github profile, and he is obviously well known in the community for the projects you mentioned, as well as hugo). In contrast, codegangsta is a good developer who made some (in my opinion) excellent packages, and some controversial as well (codegangsta/inject). Based on this, very subjective criteria, for my 12fa of docker&go ebook (<a href="https://leanpub.com/12fa-docker-golang" rel="nofollow">leanpub</a>) I'm looking at spf13/viper at the moment, even if some other package might better suit my needs. Of course, ultimately the decision to keep it might depend on how large of a portion of the complete package you tend to utilize and any additional needs you have.</p>
<p>Also, programmers have preferences. Docker is a huge ship and it's not at least surprising that some of their programmers might have been familiar with either cobra or urfave/codegangsta/cli before and chose that to work within their team. People tend to pick familiar technology to them, unless they are NodeJS developers or something and pick up every shiny new thing that comes their way.</p></pre>geodel: <pre><blockquote>
<p>People tend to pick familiar technology to them, unless they are NodeJS developers or something and pick up every shiny new thing that comes their way.</p>
</blockquote>
<p>This is good :-)</p></pre>earthboundkid: <pre><p>Spf13 only recently joined Google. His libraries were popular well before that. </p></pre>broady: <pre><p>spf13 wrote those packages well before he joined Google. And for what it's worth, spf13 isn't the primary maintainer of cobra.</p>
<p>I've used cobra. It's good. It has some oddities, but overall it's good.</p>
<p>It's more polished than urfave/cli, but urfave's library is also quite nice.</p>
<p>Disclaimer: I now work with spf13 at Google.</p></pre>tazjin: <pre><p>I prefer <code>urfave/cli</code> because no code generation is involved.</p></pre>Redundancy_: <pre><p>To be fair, I believe that spf13/cobra provides code generation as a convenience not a requirement.</p></pre>nemith: <pre><p>I agree the code generation is a huge turn off when i first read the docs. I use spf13/cobra and do zero code generation. I also don't break out my cli handlers into another package, package main is where they belong ;)</p></pre>Decateron: <pre><p>Kind of off topic, but are there really no good options aside from <a href="https://github.com/jawher/mow.cli" rel="nofollow">mow.cli</a> if you want argument validation in Go? I've been wanting to port a cli tool from Python to Go, but all of the cli packages leave a lot to be desired in that respect.</p></pre>
这是一个分享于 的资源,其中的信息可能已经有所发展或是发生改变。
入群交流(和以上内容无关):加入Go大咖交流群,或添加微信:liuxiaoyan-s 备注:入群;或加QQ群:692541889
- 请尽量让自己的回复能够对别人有帮助
- 支持 Markdown 格式, **粗体**、~~删除线~~、
`单行代码`
- 支持 @ 本站用户;支持表情(输入 : 提示),见 Emoji cheat sheet
- 图片支持拖拽、截图粘贴等方式上传