by woodruffw · 4y ago · 0 comments
* Using short options in scripts. Scripts should almost always use long options. As a corollary, tools should always provide long options unless the tool isn't intended for scripting.
* Lack of discoverability. We still don't have a standard way to ask an arbitrary tool which flags it supports, or for a rough semantic mapping of those flags (e.g. the classic -v/-V verbose and version confusion). Developing a standard here would go a long way towards automating things like tab completion without each tool needing to maintain N scripts for N shells or having its own slightly-different `--completions=SHELL` generator.
Which is exactly what powershell does: Commands in powershell (called "cmdlets") are like functions with type hints. A command does not parse the input strings itself, rather it exposes this type information to the shell. The shell is the one responsible for discovering the parameters (and types) and parsing the command line parameters and coercing types before passing them (strongly typed) to the actual command.
This means that the information about parameter names and types is readily available for doc-generation, auto tab-completion and language servers which allow syntax highlighting, completion etc to work even inside editors such as vscode or emacs.
The point is that to specify a cmdket you must declare parameters, in much the same way that for a function in a programming language to accept parameters it must declare those as formal parameters.
The real dream would be some kind of standard way for a program to indicate that it's opting into more intelligent CLI handling without any execution. I've thought about trying to hack something like that together with a custom ELF section, but that wouldn't fly for programs written in scripting languages.
This sort of sounds like what we're working on at Fig. We've defined a declarative standard for specifying the inputs to a CLI tool and have a community repo with all supported tools: https://github.com/withfig/autocomplete
Disclosure: I'm one of the founders
And documentation, or when answering questions. SE answers are often like "just type `blah -jraiorjg` and you're done", which means having to look up all these options in the manual. Short options should be the exception, when working in the shell mostly, not the rule.
And specifying field delimiters: -d in cut, -t in sort, -F in awk.
As for discoverability: again, that's what man pages are for.
It's also not relevant in the context of shell scripting with tools that aren't intended to be part of POSIX or any other standard. Plenty of ecosystems and workflows are built on proprietary, internal, or just not standardized tools.
https://pkgs.alpinelinux.org/package/edge/main/x86_64/coreut...