Question

Let's say I provide the following long option arguments structure:

static const struct option long_opts[] = {
    { "version",   no_argument,       NULL, 'v' },
    { "help",      no_argument,       NULL, 'h' },
    { NULL, 0, NULL, 0 } 
};

How can I specify an additional option, named '--myoption', but without the short form? So I would be able to call only:

./binary --myoption

I need this because I ran out of letters.

Was it helpful?

Solution

If you don't put that option into shortopts then no short option for that parameter will be used. E.g.:

#define MYOPT 1000

static struct option long_options[] = {
    {"myopt", no_argument, 0, MYOPT },
}

[...]

c = getopt_long(argc, argv, "", long_options, &option_index);
switch (c) {
case MYOPT:
    /* Do stuff. */
    break;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top