commandline icon indicating copy to clipboard operation
commandline copied to clipboard

Using dash "-" to define stdout not working

Open ericnewton76 opened this issue 8 years ago • 3 comments

Issue by TheDeadCode Saturday Aug 05, 2017 at 18:08 GMT Originally opened as https://github.com/gsscoder/commandline/issues/466


A bit like wget where you can do wget https://someurl -O - to say to output to stdout. Although I cannot get it to work:

./generator.exe -o -

ERROR(S):
  Option 'o, output' has no value.
  Required option 'o, output' is missing.

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by nemec Tuesday Aug 08, 2017 at 06:14 GMT


I'm not sure the library accepts - as a standalone value. Can you use something else for your purposes?

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Comment by ericnewton76 Tuesday Aug 08, 2017 at 13:23 GMT


The '-' for specifying "input from stdin" is a one of two common conventions on *nix utilities. This library doesn't support that. You could use the other common convention, of "if no file is specified, used stdin for input" or you could go with these alternatives:

  • use --stdin option to specify input from stdin
  • use --file or a file parameter that is empty to switch the "mode of input" to stdin instead of the specified file

The other alternative could be search the arg[] to detect the '-' by itself and set your own stdin=true flag before passing it into the library

ericnewton76 avatar Nov 04 '17 18:11 ericnewton76

Shall we support a single '-' option, like

[Option('-')]
public bool FromStdin { get; set; }

A single '-' is special and only for a bool property. Then users can follow the *nix convention, like

some-command ... -

The official support has the following benefits:

  1. Usage help is auto generated, including the option '-'.
  2. User has to specify '-' explicitly when whey want to read from stdin, instead of the program read stdin by default on some condition, in which case the program may appear hang if no input. That's not unusual if a user is not familiar with the program usage.

It would be great if we could have it.

coin8086 avatar Mar 08 '24 08:03 coin8086