TE
科技回声
首页24小时热榜最新最佳问答展示工作
GitHubTwitter
首页

科技回声

基于 Next.js 构建的科技新闻平台,提供全球科技新闻和讨论内容。

GitHubTwitter

首页

首页最新最佳问答展示工作

资源链接

HackerNews API原版 HackerNewsNext.js

© 2025 科技回声. 版权所有。

Show HN: Generate cli code in Go using static analysis

4 点作者 buchanae超过 6 年前

1 comment

buchanae超过 6 年前
Essentially, you can write CLI code using functions and struct types following a certain convention, and then use these tools to generate code for flags, env vars, config files, subcommands, etc.<p><pre><code> func AddTask(opt Opt, path string) </code></pre> ...will be turned into a CLI command &quot;add task&quot; where all the fields of &quot;Opt&quot; can be set via flags&#x2F;env&#x2F;yaml, and the positional args are mapped in too. Default values are taken from &quot;DefaultOpt()&quot;, if it exists.<p>I&#x27;ve written a number of Go apps now, and I always feel like CLI + config is a struggle. This is my latest attempt to distill all that experience into something I can reuse. It&#x27;s still rough around the edges, but the armature is there now. Hopefully you can get a feel for what it is and where it&#x27;s headed. There&#x27;s still a long list of additions and cleanups I want to make.<p>Thanks in advance for any feedback!