TE
TechEcho
Home24h TopNewestBestAskShowJobs
GitHubTwitter
Home

TechEcho

A tech news platform built with Next.js, providing global tech news and discussions.

GitHubTwitter

Home

HomeNewestBestAskShowJobs

Resources

HackerNews APIOriginal HackerNewsNext.js

© 2025 TechEcho. All rights reserved.

Don't write command-line interfaces (and how to write if you have to)

13 pointsby arogozhnikovover 4 years ago

8 comments

csb6over 4 years ago
&gt; How do you test CLI?<p>I do not understand this. Has the author used <i>diff</i> or stdin&#x2F;stdout redirection? Testing CLI is trivial in comparison to testing a GUI or another kind of interface; it is all text and so can easily be compared against a correct result. CLIs are not meant for every task, but one of their core advantages is ease of automation and testing.
评论 #24736342 未加载
评论 #24736277 未加载
ezekiel68over 4 years ago
Strong disagree.<p>Any system worth keeping around should be a library (or family of libraries) which have a CLI fronting it that serves to pass parameters to it just as you might any other way (such as through some other program or REST API or GUI). Agree the CLI &quot;shell&quot; around the system should not have separate logic, but should report back logic faults from within the library.
评论 #24769104 未加载
评论 #24736302 未加载
tenebrisalietumover 4 years ago
I <i>think</i> this is trying to say you shouldn&#x27;t build CLI parsing logic into your core functionality, and this makes sense.<p>Core functionality should be in functions, classes, etc. and a CLI utility can be separately written or synthesized that imports that library, and anything wanting to implement a different interface can do the same.<p>Isn&#x27;t that the way it&#x27;s normally done? Real world example is libcurl and curl command.
评论 #24736312 未加载
samatmanover 4 years ago
This... isn&#x27;t persuasive. I&#x27;m genuinely struggling to find a deeper critique than that.<p>Perhaps if there were examples of all the confident statements? But they&#x27;re just terse declarative sentences, all I could say is &quot;nuh uh!&quot;
评论 #24735782 未加载
olejorgenbover 4 years ago
I read the core argument as:<p>Don&#x27;t write a shell CLI prematurely - a script in whatever language you&#x27;re using can often be just as good a interface. Maintaining a shell CLI is work.<p>If you write a shell CLI don&#x27;t aim for full flexibility - a script already fulfill that role.<p>I&#x27;m a big fan of shell CLIs (command --option=1), but I think this way of thinking has merit. I would consider a script a subset of CLIs though, using a python REPL with preloaded modules is certainly a type of CLI, no? Code is a sequence of commands.<p>That being said, as the author mentions, new libaries make it really easy to expose some functions to a shell CLI. If the task mesh well with piping, exposing some primitive to the shell is probably worth it.
评论 #24740927 未加载
carydover 4 years ago
I prefer node with commander. It doesn&#x27;t get any easier or more featured than that. You can even wrap it with an API to make it graphical.
评论 #24735587 未加载
loloquwowndueoover 4 years ago
It is click bait, none of the arguments hold.
评论 #24735694 未加载
chmaynardover 4 years ago
The premise is not worth criticizing. I wonder what his motivation was for writing this nonsense?