Search code examples
cargumentsrsync

Adding arguments to options in Rsync


I am developing an application which uses the Rsync. I have added an option for HTTP in rsync code like '-v' for "--verbose".

But now I want to make that option to take the arguments. For that in options.c file, I have added the entry in the array of structure as,

static struct poptOption long_options[] = {
  /* longName, shortName, argInfo, argPtr, value, descrip, argDesc */
  {"xxxx",             'x',  xxxxxxx,   x, xxxxx, x, x},
  {"https",            'N', POPT_ARG_VAL,    &https_port, 0, 0, 0}}  

Here the value I have provided should come in variable https_port. But I get the error as

Rsync: -N=1234: option does not take an argument

Where I need to make changes more to make N option to take an arguments.

Thanks


Solution

  • You must parse the arg as POPT_ARG_STRING instead of POPT_ARG_VAL, and then convert it to an integer (or whatever).

    See the max-size implementation as an example:

    {"max-size",         0,  POPT_ARG_STRING, &max_size_arg, OPT_MAX_SIZE, 0, 0 },