I have a tool that takes input and makes output:
$ tool input > output
I’d like to add an option that is a long string — say, a “comment” option. This comment text is an argument to the option and is a sentence enclosed in forward tick marks:
$ tool --comment='I am commenting on the use of comments' input > output_plus_comment
This is different from the usual --foo=bar key-value pairing, where foo is the option name and bar is a one-word value (e.g., true, red, …).
Is there a good command-line parser library for C that handles this particular case?
Tokenizing the command line into arguments for your program is the responsibility of your shell, not yours. So there’s nothing for you to do.
Just put quotation marks around strings that contain spaces, or escape spaces with backslashes on your command line, and your
--foovalue can contain as many spaces as you like.