Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support for positional and ... arguments #40

Closed
jkcko opened this issue Jul 11, 2018 · 2 comments
Closed

Support for positional and ... arguments #40

jkcko opened this issue Jul 11, 2018 · 2 comments

Comments

@jkcko
Copy link

jkcko commented Jul 11, 2018

I needed handling of positional arguments as well as one or more arguments so I made some changes which you can find here.

jkcko@23a68dd

The Command type now includes a pointer to an Argument array which lists the positional arguments for the command.

Additional Argument arrays with prefix docopt_ are generated for each command.

parse_argcmd will now assign value in the matching argument of elements->arguments and the positional docopt_ arrays.
argument->value = argument value
argument->count = number of arguments on the command line including this one (for counting ...)
argument->array = points to argv for this argument (for ...)

Usage for positional arguments would be something like.

   cfg command <arg1> <arg2> <arg3>

   if (arg.arg1 != NULL) {
       printf("arg1 %s\n", arg.arg1);
   }
   if (arg.arg2 != NULL) {
       printf("arg2 %s\n", arg.arg2);
   }
   if (arg.arg3 != NULL) {
       printf("arg3 %s\n", arg.arg3);
   }

Usage for ... would be something like.

   cmd command <list-item>...

    if (docopt_command[0].count > 1) {
        /* more than one */
        char **array = docopt_command[0].array;
        for (i=0; i < count; i++) {
            list_item[i] = array[i];
        }
    }
    else {
        /* one */
        char *strp = args->command;
    }

Caveat: [options] combined with positional arguments is not supported.

@jkcko
Copy link
Author

jkcko commented Jul 16, 2018

I've made a number of improvements to my fork and it now works with [options] either before or after the required positional arguments. The naval fate example now works.

@jkcko
Copy link
Author

jkcko commented Jul 23, 2018

This is a duplicate of #32.

@jkcko jkcko closed this as completed Jul 23, 2018
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant