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.

Ask HN: Why is there no specification for Command Line Interfaces?

15 pointsby digitalsanctumabout 2 years ago
Similar to specifications like OpenAPI, etc. it seems like having something similar for CLIs would be cool. Why isn&#x27;t there one already? How do you approach stubbing a CLI to interface with one or more APIs?<p>Edit: I forgot to mention the closest thing I&#x27;ve found is: https:&#x2F;&#x2F;clig.dev&#x2F; which is the most comprehensive &quot;guide&quot; I&#x27;ve seen to date.

12 comments

Someoneabout 2 years ago
For guidelines, there also are:<p>- GNU: <a href="https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;html_node&#x2F;Command_002dLine-Interfaces.html" rel="nofollow">https:&#x2F;&#x2F;www.gnu.org&#x2F;prep&#x2F;standards&#x2F;html_node&#x2F;Command_002dLin...</a><p>- POSIX: <a href="https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1_chap12.html" rel="nofollow">https:&#x2F;&#x2F;pubs.opengroup.org&#x2F;onlinepubs&#x2F;9699919799&#x2F;basedefs&#x2F;V1...</a>
bobbiechenabout 2 years ago
What&#x27;s the use case? I was thinking about this exact issue because my product ships several CLI tools, but I wasn&#x27;t convinced it would be worth the effort.<p>An OpenAPI specification describes an HTTP interface, and I see it as useful because it makes it easier to write code in language-of-choice to generate HTTP requests (by generating client libraries from the OpenAPI spec).<p>For a CLI, the interface is the command-line. Usually people type these commands, or they end up in bash scripts, or sometimes they get called from programming language of choice by shelling out to the CLI. So I could see a use case for a CLI spec, which would make it easier to generate client libraries (which would shell out to the CLI)... but it seems a little niche.<p>Or maybe, as input to a documentation tool (like Swagger docs). I would imagine if you&#x27;re using a CLI library like Python&#x27;s Click, most of that data is already there. Click Parameters documentation: <a href="https:&#x2F;&#x2F;click.palletsprojects.com&#x2F;en&#x2F;8.1.x&#x2F;parameters&#x2F;" rel="nofollow">https:&#x2F;&#x2F;click.palletsprojects.com&#x2F;en&#x2F;8.1.x&#x2F;parameters&#x2F;</a><p>Or maybe, you could start from the spec and then generate code which enforces it. So any changes pass through the spec, which would make it easy to write code (server and client-side) &#x2F; documentation &#x2F; changelogs. Some projects like this: Guardrail (Scala) <a href="https:&#x2F;&#x2F;github.com&#x2F;guardrail-dev&#x2F;guardrail">https:&#x2F;&#x2F;github.com&#x2F;guardrail-dev&#x2F;guardrail</a> , and Connexion (Python) <a href="https:&#x2F;&#x2F;github.com&#x2F;spec-first&#x2F;connexion">https:&#x2F;&#x2F;github.com&#x2F;spec-first&#x2F;connexion</a> .<p>But without this ecosystem of tooling, documenting your CLI in a specification didn&#x27;t really seem worth the effort. Of course, that&#x27;s a bootstrapping problem.
评论 #34961657 未加载
ezekgabout 2 years ago
I dug around my refs and I was about to recommend <a href="https:&#x2F;&#x2F;clig.dev&#x2F;" rel="nofollow">https:&#x2F;&#x2F;clig.dev&#x2F;</a>, but I see you&#x27;ve already found it. It&#x27;s a great little reference to have when building a CLI. I typically read the code for other CLIs, particularly those written with the framework I&#x27;m using. The last framework I used was Cobra [0], and I studied how others did theirs:<p>- <a href="https:&#x2F;&#x2F;cs.github.com&#x2F;?scopeName=All+repos&amp;scope=&amp;q=github.com%2Fspf13%2Fcobra+path%3A*.go+NOT+kubernetes" rel="nofollow">https:&#x2F;&#x2F;cs.github.com&#x2F;?scopeName=All+repos&amp;scope=&amp;q=github.c...</a><p>[0]: <a href="https:&#x2F;&#x2F;github.com&#x2F;spf13&#x2F;cobra">https:&#x2F;&#x2F;github.com&#x2F;spf13&#x2F;cobra</a>
andrewfromxabout 2 years ago
I think they mean why is it sometimes &quot;.&#x2F;foo --help&quot; vs &quot;.&#x2F;foo -h&quot; or &quot;.&#x2F;thing --other=123 --value=456&quot; but sometimes &quot;.&#x2F;thing -o 123 -v 456&quot;
评论 #34964820 未加载
MathMonkeyManabout 2 years ago
Maybe for the same reason that there&#x27;s no specification for command line tool stdin&#x2F;stdout aside from &quot;text.&quot;<p>Command line arguments are an array of null-terminated strings, as is the environment (at least there we have the convention &quot;&lt;key&gt;=&lt;value&gt;&quot;).<p>It might be neat to define a schema language together with a validator that takes a schema and a &quot;style&quot; and then validates an array of strings. e.g. &quot;validate gnu myschema.ext -- subcommand --flag -etc --thing=value arg arg&quot;.
revskillabout 2 years ago
Just like: there&#x27;s no specification for function parameters and results.<p>Specification is too strict in this case, so it&#x27;s less useful than &quot;best practices&quot; which&#x27;s adapt to a context.
bradwoodabout 2 years ago
Same reason there is no specification for GUI interfaces.<p>There are trends, and patterns, and conventions in both GUI and CLI design but it&#x27;s always going to be about the UX, the use case, the target audience, etc.
vivegiabout 2 years ago
Well, in a sense there is a spec, at the lowest level.<p>As an example, for a C program you have<p><pre><code> int main(int argc, char **argv) { ... } </code></pre> From there, it is just conventions on what the arguments mean.
hayst4ckabout 2 years ago
Can you go into more detail about the problems you think might be solved?
评论 #34961581 未加载
yuppie_scumabout 2 years ago
This x1000<p>Especially in the DevOps space, I find one CLI’s “update” will be another’s “apply”, one “delete” will be another “remove“, add&#x2F;create, etc. It adds excessive cognitive load.
评论 #34964916 未加载
warrenmabout 2 years ago
PowerShell does this for .NET, doesn&#x27;t it?<p>By &quot;CLI&quot; do you mean &quot;shell interpreter&#x2F;environment&quot;?<p>Or do you mean &quot;command-line interface for a given tool&quot;
ironmagmaabout 2 years ago
Because it&#x27;s an API presenting as a human interface. It&#x27;s a confused concept altogether.