digitalmars.D - getopt & single-letter options with parameters
- Adrian Matoga (22/24) Aug 07 2010 Hi,
- Andrei Alexandrescu (8/32) Aug 07 2010 It's by design in order to avoid confusion with parameterless options.
- Adrian Matoga (5/51) Aug 07 2010 Thanks very much.
- Andrei Alexandrescu (3/54) Aug 08 2010 http://www.dsource.org/projects/phobos/changeset/1822
- Adrian Matoga (5/18) Aug 08 2010 Thank you, now the description is clear.
- SK (1/18) Aug 07 2010
- SK (9/51) Aug 07 2010 charset=us-ascii;
- Andrei Alexandrescu (3/17) Aug 07 2010 Sure. A patch would actually help a lot.
- Jonathan M Davis (3/4) Aug 07 2010 Well, just so long as no one dereferenced it... ;)
- Nick Sabalausky (13/14) Aug 08 2010 That being allowed at all kind of bugs me. I realize this probably isn't...
- Andrei Alexandrescu (4/19) Aug 08 2010 Short options with parameters don't accept bundling, so the problem
- Andrei Alexandrescu (3/31) Aug 08 2010 Actually I stand corrected. The tar program does use bundled parameters....
- Nick Sabalausky (6/33) Aug 08 2010 This then:
- Andrei Alexandrescu (4/39) Aug 08 2010 The long form with parameters accepts "--name=value" and "--name value"
Hi, Is it by design that single-letter option needs to be glued to its argument, like "-ofilename", or is it a bug in implementation? Source: import std.stdio; import std.getopt; void main(string[] args) { string outputFile; getopt(args, config.passThrough, "o|output-filename", &outputFile); writeln(args); writeln("'" ~ outputFile ~ "'"); } Results:test.exe -o somenametest.exe somename ''test.exe -osomenametest.exe 'somename' Regards, Adrian Matoga
Aug 07 2010
On 08/07/2010 05:55 PM, Adrian Matoga wrote:Hi, Is it by design that single-letter option needs to be glued to its argument, like "-ofilename", or is it a bug in implementation? Source: import std.stdio; import std.getopt; void main(string[] args) { string outputFile; getopt(args, config.passThrough, "o|output-filename", &outputFile); writeln(args); writeln("'" ~ outputFile ~ "'"); } Results: >test.exe -o somename test.exe somename '' >test.exe -osomename test.exe 'somename' Regards, Adrian MatogaIt's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. Andrei
Aug 07 2010
On 2010-08-08 01:22, Andrei Alexandrescu wrote:On 08/07/2010 05:55 PM, Adrian Matoga wrote:Thanks very much. I suggest adding this info to official docs (it's not obvious, and a bit confusing, since long options work with whitespace(s)). AdrianHi, Is it by design that single-letter option needs to be glued to its argument, like "-ofilename", or is it a bug in implementation? Source: import std.stdio; import std.getopt; void main(string[] args) { string outputFile; getopt(args, config.passThrough, "o|output-filename", &outputFile); writeln(args); writeln("'" ~ outputFile ~ "'"); } Results: >test.exe -o somename test.exe somename '' >test.exe -osomename test.exe 'somename' Regards, Adrian MatogaIt's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. Andrei
Aug 07 2010
On 08/07/2010 06:57 PM, Adrian Matoga wrote:On 2010-08-08 01:22, Andrei Alexandrescu wrote:http://www.dsource.org/projects/phobos/changeset/1822 AndreiOn 08/07/2010 05:55 PM, Adrian Matoga wrote:Thanks very much. I suggest adding this info to official docs (it's not obvious, and a bit confusing, since long options work with whitespace(s)). AdrianHi, Is it by design that single-letter option needs to be glued to its argument, like "-ofilename", or is it a bug in implementation? Source: import std.stdio; import std.getopt; void main(string[] args) { string outputFile; getopt(args, config.passThrough, "o|output-filename", &outputFile); writeln(args); writeln("'" ~ outputFile ~ "'"); } Results:It's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. Andreitest.exe -o somenametest.exe somename ''test.exe -osomenametest.exe 'somename' Regards, Adrian Matoga
Aug 08 2010
http://www.dsource.org/projects/phobos/changeset/1822 AndreiThank you, now the description is clear. By the way, shouldn't "--FOo" and "--bAr" in the following fragment be rejected because of "caseSensitive" set just before them?By default options are case-insensitive. You can change that behavior by passing $(D getopt) the $(D caseSensitive) directive like this: --------- bool foo, bar; getopt(args, std.getopt.config.caseSensitive, "foo", &foo, "bar", &bar); --------- In the example above, "--foo", "--bar", "--FOo", "--bAr" etc. arerecognized. Adrian
Aug 08 2010
On Aug 7, 2010, at 4:22 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.orgwrote:It's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. Andrei
Aug 07 2010
charset=us-ascii; format=flowed; delsp=yes Content-Transfer-Encoding: 7bit On Aug 7, 2010, at 4:22 PM, Andrei Alexandrescu <SeeWebsiteForEmail erdani.orgwrote:On 08/07/2010 05:55 PM, Adrian Matoga wrote:The prevailing convention is to allow whitespace in this case. Would you reconsider? Sorry for the accidental null post earlier. -steveHi, Is it by design that single-letter option needs to be glued to its argument, like "-ofilename", or is it a bug in implementation? Source: import std.stdio; import std.getopt; void main(string[] args) { string outputFile; getopt(args, config.passThrough, "o|output-filename", &outputFile); writeln(args); writeln("'" ~ outputFile ~ "'"); } Results:It's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. Andreitest.exe -o somenametest.exe somename ''test.exe -osomenametest.exe 'somename' Regards, Adrian Matoga
Aug 07 2010
On 08/07/2010 10:08 PM, SK wrote:Sure. A patch would actually help a lot. AndreiIt's by design in order to avoid confusion with parameterless options. Your example works with either of these invocations: ./prog -ofilename ./prog -o=filename ./prog --o=filename but not others. AndreiThe prevailing convention is to allow whitespace in this case. Would you reconsider?
Aug 07 2010
On Saturday 07 August 2010 20:08:26 SK wrote:Sorry for the accidental null post earlier.Well, just so long as no one dereferenced it... ;) - Jonathan M Davis
Aug 07 2010
"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:i3kpsi$rod$1 digitalmars.com..../prog -ofilenameThat being allowed at all kind of bugs me. I realize this probably isn't a particularly common problem in practice, but suppose you have: -o<filename> -of And the user uses "-o" with a file named "f": theapp -of // Do what now? Or, -o<filename> -of<filename> theapp -ofabc // "-o fabc" or "-of abc"? The whole possibility kinda makes me nervous.
Aug 08 2010
On 08/08/2010 12:17 PM, Nick Sabalausky wrote:"Andrei Alexandrescu"<SeeWebsiteForEmail erdani.org> wrote in message news:i3kpsi$rod$1 digitalmars.com...Short options with parameters don't accept bundling, so the problem never shows itself. Andrei./prog -ofilenameThat being allowed at all kind of bugs me. I realize this probably isn't a particularly common problem in practice, but suppose you have: -o<filename> -of And the user uses "-o" with a file named "f": theapp -of // Do what now? Or, -o<filename> -of<filename> theapp -ofabc // "-o fabc" or "-of abc"? The whole possibility kinda makes me nervous.
Aug 08 2010
On 08/08/2010 02:37 PM, Andrei Alexandrescu wrote:On 08/08/2010 12:17 PM, Nick Sabalausky wrote:Actually I stand corrected. The tar program does use bundled parameters... Andrei"Andrei Alexandrescu"<SeeWebsiteForEmail erdani.org> wrote in message news:i3kpsi$rod$1 digitalmars.com...Short options with parameters don't accept bundling, so the problem never shows itself. Andrei./prog -ofilenameThat being allowed at all kind of bugs me. I realize this probably isn't a particularly common problem in practice, but suppose you have: -o<filename> -of And the user uses "-o" with a file named "f": theapp -of // Do what now? Or, -o<filename> -of<filename> theapp -ofabc // "-o fabc" or "-of abc"? The whole possibility kinda makes me nervous.
Aug 08 2010
"Andrei Alexandrescu" <SeeWebsiteForEmail erdani.org> wrote in message news:i3n12a$2vfq$1 digitalmars.com...On 08/08/2010 12:17 PM, Nick Sabalausky wrote:This then: --xy<filename> --xyz<filename> theapp --xyzabc // "--xy zabc" or "-xyz abc"?"Andrei Alexandrescu"<SeeWebsiteForEmail erdani.org> wrote in message news:i3kpsi$rod$1 digitalmars.com...Short options with parameters don't accept bundling, so the problem never shows itself../prog -ofilenameThat being allowed at all kind of bugs me. I realize this probably isn't a particularly common problem in practice, but suppose you have: -o<filename> -of And the user uses "-o" with a file named "f": theapp -of // Do what now? Or, -o<filename> -of<filename> theapp -ofabc // "-o fabc" or "-of abc"? The whole possibility kinda makes me nervous.
Aug 08 2010
On 08/08/2010 04:02 PM, Nick Sabalausky wrote:"Andrei Alexandrescu"<SeeWebsiteForEmail erdani.org> wrote in message news:i3n12a$2vfq$1 digitalmars.com...The long form with parameters accepts "--name=value" and "--name value" but not "--namevalue". AndreiOn 08/08/2010 12:17 PM, Nick Sabalausky wrote:This then: --xy<filename> --xyz<filename> theapp --xyzabc // "--xy zabc" or "-xyz abc"?"Andrei Alexandrescu"<SeeWebsiteForEmail erdani.org> wrote in message news:i3kpsi$rod$1 digitalmars.com...Short options with parameters don't accept bundling, so the problem never shows itself../prog -ofilenameThat being allowed at all kind of bugs me. I realize this probably isn't a particularly common problem in practice, but suppose you have: -o<filename> -of And the user uses "-o" with a file named "f": theapp -of // Do what now? Or, -o<filename> -of<filename> theapp -ofabc // "-o fabc" or "-of abc"? The whole possibility kinda makes me nervous.
Aug 08 2010