News for hackers. Stuff that matters.
Re:Exploring CLI Best Practices by jpitz on Tuesday October 11, 2016 @04:13PM (#12688121)
While I agree that v0.1 should support stdin/stdout, I don't know that you are serving all of your users well by limiting i/o to ONLY stdin/out.
Re:Exploring CLI Best Practices by lucb1e on Tuesday October 11, 2016 @04:54PM (#12688443)
The two applications for specifying files on the command line is when: they actually do something with that file (e.g. move the file) or when you operate on multiple files and/or directories (e.g. backup application).

Otherwise it still might be useful, but in general it's kind of unnecessary. It adds logic to your application that it doesn't need, which violates "do one thing, and one thing very well" (albeit only a very small violation).

Re:Exploring CLI Best Practices by jpitz on Tuesday October 11, 2016 @05:38PM (#12688727)
ISTM that you're arguing from a perspective of intrinsic necessity. Your argument is that, anyone can cat a file into my utility, if they need that functionality.

Sure. However, for example, GNU sort doesn't work that way. Most utilities don't work that way. Most utilities accept a file as an source of input, and most of those don't act on the inode. That's the status quo.

Re:Exploring CLI Best Practices by marvy on Tuesday October 11, 2016 @11:27PM (#12690252)
sort is a bad example: to support sorting in-place, it has to know the file name. Pity the user who typed

    sort < bigfile > bigfile
for said user just lost a file.
Re:Exploring CLI Best Practices by d0mine on Wednesday October 12, 2016 @12:52AM (#12690494)
A general solution is something like:

  $ sort "$name" | sponge "$name"
Check whether:

  $ sort -o "$name" "$name" 
works with your version of the sort utility.
Re:Exploring CLI Best Practices by shabble on Wednesday October 12, 2016 @05:38PM (#12696601)
This has bitten me occasionally, even though I know the workarounds (tempfiles or pipe-consumers like sponge(1)).

I'm wondering if there's any practical use for the behaviour, or if it's worth hacking a shell such that it produces a warning/interactive confirm prompt for it (or transparently buffers to DWIM maybe?)

Re:Exploring CLI Best Practices by eichin on Monday October 17, 2016 @03:40PM (#12728766)
It's pretty common to `set -o noclobber` in beginner dotfiles; doing deferred-open-if-exists is an interesting idea that would probably get a lot of resistance :-)
Re:Exploring CLI Best Practices by dllthomas on Tuesday October 11, 2016 @05:40PM (#12688749)
A third is "it uses multiple files (and the behavior can't be replicated by concatenating them)."

Picking one input to still be consumed from stdin can make sense, though. A special case of this is config files, which are almost never read from stdin (they usually have a default location or several).

Re:Exploring CLI Best Practices by Annatar on Wednesday October 12, 2016 @03:45AM (#12691031)
Outputting to stdout gives the control and power to the user - if they want it in a file which they want to name, they can do that; if they want to pass the output as input to another application - they can do that too.

There are few usage scenarios where such behavior isn't enough, like for example fsck, but even there this paradigm is flexible enough to work - for such applications could be split into an analyzer and a repair program. There is nothing stopping one from outputting a binary data stream on stdout; Lots of applications do exactly that on UNIX, compressors come to mind.

What use case have you where stdout/stdin/stderr isn't enough on an operating system family where the core paradigm of usage is that everything is a binary stream of data?

Re:Exploring CLI Best Practices by jpitz on Wednesday October 12, 2016 @10:44AM (#12693287)
> Outputting to stdout gives the control and power to the user - if they want it in a file which they want to name, they can do that; if they want to pass the output as input to another application - they can do that too.

Please note that we already agree here.

> What use case have you where stdout/stdin/stderr isn't enough on an operating system family where the core paradigm of usage is that everything is a binary stream of data?

My argument isn't that I have a use case where it 'isn't enough.' My argument is that many people come to a cli utility expecting that <foo /path/to/myfile> simply works.

Re:Exploring CLI Best Practices by Annatar on Wednesday October 12, 2016 @12:34PM (#12694330)
My argument is that many people come to a cli utility expecting that <foo /path/to/myfile> simply works.

So are for or against that? If you're for the < /path/to/my/file argument, then we are in complete agreement. A command line application should read from stdin where that applies.

Re:Exploring CLI Best Practices by dllthomas on Wednesday October 12, 2016 @01:38PM (#12694950)
It seems to me there was confusion here caused by an unfortunate choice of angle brackets for quoting.

I think `foo /path/to/myfile` is what the parent was trying to say.

Re:Exploring CLI Best Practices by jpitz on Wednesday October 12, 2016 @02:10PM (#12695212)
It was. Thank you.

I want stdin to work. I also want specifying a file name to work. I think supporting both is good UI design, and follows the principle of least surprise.