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

科技回声

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

GitHubTwitter

首页

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

资源链接

HackerNews API原版 HackerNewsNext.js

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

Create a fully functioning command line interface with 1.5 lines of code

43 点作者 vitaut将近 5 年前

11 条评论

bdcravens将近 5 年前
I can also write a fully functioning web application in 1 line of code if I exclude how big each dependency is.
评论 #24095565 未加载
butz将近 5 年前
The example is clearly 9 lines long and included fire.hpp has 703 lines of source code excluding comments.
评论 #24097390 未加载
femto113将近 5 年前
If we&#x27;re playing CLI golf why not use macros to make it even dryer?<p><pre><code> int fired_main(int x = fire::arg(&quot;-x&quot;), int y = fire::arg(&quot;-y&quot;)) </code></pre> could just be<p><pre><code> int fired_main(int fire_arg(x), int fire_arg(y)) </code></pre> with something like<p><pre><code> #define fire_arg(v) v = fire::arg(&quot;-&quot;#v) </code></pre> The C preprocessor is still the thing I miss most when working in any other language.
giomasce将近 5 年前
It&#x27;s unfortunate you can&#x27;t just write something like:<p><pre><code> FIRE(args) { &#x2F;&#x2F; ... } </code></pre> without the explicit registration step. Unfortunately in this case the macro FIRE should first declare the fired function, then main, then defined the fired function, and this would be problematic because the definition can&#x27;t have the default values for arguments again. I can&#x27;t see a way around that.
Jare将近 5 年前
Funny, jut a couple days ago I started using dotnet&#x27;s System.CommandLine.DragonFruit which is similar in design philosophy to this - a main function with typed parameters and extra annotations. I would have never thought about this type of approach, or if I did I likely would have rejected it outright in favor of more typical classes &#x2F; functions to do it, but I admit it&#x27;s convenient for a quick tool.
thiagocsf将近 5 年前
This reminds me of Click for Python in that the CLI is built based on the functions that describe the commands and arguments.<p>Click uses decorators though. I don’t know what the C++ equivalent could be.
x87678r将近 5 年前
I&#x27;d love a good library to handle an interactive prompt and state machine. You know press 1&#x2F;2&#x2F;3 for x&#x2F;y&#x2F;z etc. Java especially
ncmncm将近 5 年前
Somebody should explain that std::endl instead of &#x27;\n&#x27; is pointless, verbose, and also slow.
gumby将近 5 年前
Nice. boost::program_options needs a rethink for modern c++
Kiro将近 5 年前
What does 1.5 lines of code mean?
评论 #24094868 未加载
评论 #24094669 未加载
评论 #24094656 未加载
评论 #24094648 未加载
评论 #24099492 未加载
popotamonga将近 5 年前
Anything for C#?