cmdargs icon indicating copy to clipboard operation
cmdargs copied to clipboard

Comments in args file

Open alensiljak opened this issue 6 years ago • 5 comments

Please note that I am not too familiar with cmdargs but am a user of hledger, which uses cmdargs for parsing arguments stored in text files. As specified in an issue there, I find that it would be very convenient to have comments in the argument files. In case the functionality of reading the argument files is indeed part of cmdargs, would you consider ignoring lines that start with ";" (or other delimiters), for example, and leave them as comments. This might be really useful for cases when there are multiple or confusing arguments, or just temporarily removing some of them. Thanks!

alensiljak avatar May 16 '19 17:05 alensiljak

Seems a reasonable thing to do - only question is what should the comment syntax be? Can you find any other similar args files that use comments? I'd prefer to copy rather than do something different.

ndmitchell avatar May 26 '19 21:05 ndmitchell

Hi! Thanks a lot for the feedback. I'm coming from the viewpoint of parsing the arguments for ledger-style argument files, also used in hledger. Ledger supports the following characters for comments: https://www.ledger-cli.org/3.0/doc/ledger3.html#Commenting-on-your-Journal

Naturally, I would not expect cmdargs to follow ledger's specs but some of those are common comment chars, like # and ;. Perhaps others, too, but I'm mostly using these two. That might be a good start?

Edit: Technically, arguments start with -- or / or a letter [A-z][a-z] or a number [0-9]? So, in theory, any other special character might a comment. But that would be too restrictive.

alensiljak avatar May 27 '19 11:05 alensiljak

Count me interested too. The recent https://www.stevegattuso.me/tech-stack/finances-budgeting.html#args has some nice examples of args files commented with #, but I'm not sure this actually works - it doesn't for me.

The only docs I have found for the argument file format are at https://stackoverflow.com/questions/53995002/where-does-shell-argument-files-or-files-originate-from .

simonmichael avatar Nov 17 '22 15:11 simonmichael

The recent https://www.stevegattuso.me/tech-stack/finances-budgeting.html#args has some nice examples of args files commented with #, but I'm not sure this actually works - it doesn't for me.

Presumably this was just an annotated example and the # comments aren't actually part of the files

bsima avatar Nov 17 '22 15:11 bsima

The implementation is here: https://github.com/ndmitchell/cmdargs/blob/master/System/Console/CmdArgs/Explicit/ExpandArgsAt.hs#L7

Ignoring lines beginning with # or whitespace and # would be easy. Correctly ignoring end-of-line # comments is harder, it would be nice not to break quoted arguments containing #. Or you could ignore shell quoting rules, as I suspect java does (https://docs.oracle.com/javase/9/tools/java.htm#JSWOR-GUID-4856361B-8BFD-4964-AE84-121F5F6CF111 : Use the number sign # in the argument file to identify comments. All characters following the# are ignored until the end of line.)

simonmichael avatar Nov 17 '22 16:11 simonmichael