5 ms·
One of my pet peeves with command line tools is where they take a list of values but also support flags. You then have no end of fun working with hyphen-prefixe
by hnlmorg 5y ago
One of my pet peeves with command line tools is where they take a list of values but also support flags. You then have no end of fun working with hyphen-prefixed file names and no end of hard to find bugs too (at least most shell script writers are aware that spaces in file names are a pain but these kinds of bugs are a lot more dangerous and easier to forget).
I can forgive a lot of design flaws because the tech was new and people didn't know any better but I always struggle to apply that same reasoning with the design of having commands that support both free text and flags that change that command's operation. I'm surprised nobody at the time paused and said "this might be a problem" when they were writing their tools and only using the hyphen to distinguish between a flag or data. Maybe I'm being a little unfair though -- it is hard to put yourself in their shoes and unlearn 50 years of tech.
My biggest peeve about it though is that I can write a shell that doesn't apply to POSIX and which fixes a lot of shortcomings of shell scripting. But I cannot fix this specific class of bugs without rewriting the entirety of coreutils.
- blueflow 5y agoDo you know about "--" ?
- hnlmorg 5y agoI do but it's not a good enough solution: - it is a GNUism so not available on all UNIX-like systems - it is something you pro-actively have to remember to put in - you cannot simply add `--` to every command because those that do not support it would fail (or worse, not fail in unexpected ways) In an ideal world operators should be out of band from data (murex does this with `config` https://murex.rocks/docs/commands/config.html https://murex.rocks/docs/commands/config.html whereas other commands might solve this with environmental variables. Neither are as convenient as flags though). In a less ideal world data should be encapsulated inside operators (see below), but this breaks globbing. command --flag1 --flag2 --data=file1 --data=file2 --data=file3 In my perfect world arguments would be typed so you could denote whether a parameter was an operator or data. However this doesn't translate well with the terse input of strings (as one does on the command line). Maybe if `--` was a standard from the beginning to act as a separator between operators and data (and enforced too, ie commands would fail if `--` wasn't present) then I'd be more forgiving for `--` as a solution.