Coder Social home page Coder Social logo

argparse's People

Contributors

a-random-lemurian avatar aschuhardt avatar bedrockjie avatar bunjdo avatar cofyc avatar cofyc-bot avatar david-croose avatar dumheter avatar eljefedelrodeodeljefe avatar falcosc avatar foosoft avatar foxieflakey avatar handledexception avatar nathan76543217 avatar pariasm avatar polluks avatar uis246 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

argparse's Issues

Description and Epilog?

Any opinions on including a description and epilog? Since this is static library, its easy enough to just edit the source files, but it seems like it would be a commonly-used feature.

Since adding args to argparse_init() breaks backwards-compatibilty, would the best way to approach this be something line:

int argparse_describe(struct argparse *self, const char *description, const char *epilog) 

called after argparse_init() to set these in the new struct argparse fields?

null pointer assignment to argv

When you assign this->output to argv, and then later on assign a null value to this->output[x], it also updates argv to have a null pointer. This is unexpected and argv shouldn't be modified.

Big Sur test (zsh)

###### Unit Test #####
ok 1
ok 2
ok 3
ok 4
ok 5
not ok 6
#   Failed test in ./tap-functions:is() at line 285.
#          got: 'error: option `-i` Invalid argument'
#     expected: 'error: option `-i` expects an integer value'
not ok 7
#   Failed test in ./tap-functions:is() at line 285.
#          got: 'error: option `-i` Result too large'
#     expected: 'error: option `-i` Numerical result out of range'
ok 8
ok 9
ok 10
not ok 11
#   Failed test in ./tap-functions:is() at line 285.
#          got: 'error: option `-s` Result too large'
#     expected: 'error: option `-s` Numerical result out of range'
ok 12
ok 13
ok 14
ok 15
ok 16
ok 17
1..17
# Looks like you failed 3 tests of 17.
make: *** [test] Error 3

Required Arguments

I think required arguments would be a great addition. As far as I know, they are not implemented.

Exit status should not be 0 on error

This project looks interesting, I look forward to using it in some projects. Thanks for your work.

When exiting due to a parsing error, argparse exits with status 0, but it should probably return EXIT_FAILURE (from stdlib.h) or EX_USAGE (from sysexits.h). If the user passes "-h", then 0 is correct, in my opinion.

Positional arguments?

The feature section on the README talks about positional arguments but no example has been shown and I can't find how it can be done even after reading the code.

subcommands

thanks for making a malloc-free arg parser that has a sane api.
any chance we could add subcommands?

thething subcommand -xyz

FP optional?

So far argparse always requires floating point support because of strtof().
What about some kind of optional implementation?

Positional arguments

Is it possible to handle positional arguments? For example, if I want to call my program like foo [options] <filename>? I don't see anything like that in the source code but I could have easily missed it.

[feature] support shell completions

Can it support generating completions for common shells? For python's argparse, we have shtab, can generate shell completion script from a template.

Solution 1: Let user do it by themselves

# After installing foo
$ foo --print-completion bash | sudo tee /usr/share/bash-completion/completions/foo
# completion can work
$ foo -<TAB>

Solution 2: Write some install() in cmake

$ cmake -Bbuild -DCMAKE_INSTALL_PREFIX=/usr
$ cmake --build build
$ cmake --install build
$ ls /usr/share/bash-completion/completions/foo
/usr/share/bash-completion/completions/foo
# completion can work
$ foo -<TAB>

I thinks solution 2 will be better?

Array options (i.e -Werror -Wall becomes {"error", "all"})

Now, if I was actually making a compiler, I probably would use a different argument parsing library. How would we deal with multiple options?

If we ran:

./a.out -Ooption1 -Ooption2

I would expect to get something along the lines of {"option1", "option2"}. Is it possible to do this, or do I have to implement this myself?

Version management

I'm planning on using this project in my GNU Moreutils vipe rewrite, I was curious what version management system this project uses. You have some git tags that seem to be Semantic Versioned but there have been quite a few bug fixes since then and no tagged version patches.

make test compiles with warnings on gcc 5.4.0

` $ make test
cc -o test_argparse.o -c -Wall -Wextra -fPIC -O3 -g -ggdb test_argparse.c
test_argparse.c: In function ‘main’:
test_argparse.c:28:9: warning: missing initializer for field ‘callback’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_BOOLEAN('f', "force", &force, "force to do"),
^
In file included from test_argparse.c:4:0:
argparse.h:80:24: note: ‘callback’ declared here
argparse_callback *callback;
^
test_argparse.c:29:9: warning: missing initializer for field ‘callback’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_BOOLEAN('t', "test", &test, "test only"),
^
In file included from test_argparse.c:4:0:
argparse.h:80:24: note: ‘callback’ declared here
argparse_callback *callback;
^
test_argparse.c:30:9: warning: missing initializer for field ‘callback’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_STRING('p', "path", &path, "path to read"),
^
In file included from test_argparse.c:4:0:
argparse.h:80:24: note: ‘callback’ declared here
argparse_callback *callback;
^
test_argparse.c:31:9: warning: missing initializer for field ‘callback’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_INTEGER('i', "int", &int_num, "selected integer"),
^
In file included from test_argparse.c:4:0:
argparse.h:80:24: note: ‘callback’ declared here
argparse_callback *callback;
^
test_argparse.c:32:9: warning: missing initializer for field ‘callback’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_FLOAT('s', "float", &flt_num, "selected float"),
^
In file included from test_argparse.c:4:0:
argparse.h:80:24: note: ‘callback’ declared here
argparse_callback *callback;
^
test_argparse.c:35:9: warning: missing initializer for field ‘flags’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_BIT(0, "write", &perms, "write perm", NULL, PERM_WRITE),
^
In file included from test_argparse.c:4:0:
argparse.h:82:9: note: ‘flags’ declared here
int flags;
^
test_argparse.c:36:9: warning: missing initializer for field ‘flags’ of ‘struct argparse_option’ [-Wmissing-field-initializers]
OPT_BIT(0, "exec", &perms, "exec perm", NULL, PERM_EXEC),
^
In file included from test_argparse.c:4:0:
argparse.h:82:9: note: ‘flags’ declared here
int flags;
^
cc -Wall -Wextra -fPIC -O3 -g -ggdb -o test_argparse argparse.o test_argparse.o

Unit Test

ok 1
ok 2
ok 3
ok 4
ok 5
ok 6
ok 7
ok 8
ok 9
ok 10
ok 11
ok 12
ok 13
ok 14
ok 15
1..15`

Make release tag

I'm doing some C code experiments using this very nice argparse implementation. I wrote a small script that clones repositories so that it's easy to install third party code such as this. For that reason it'd be preferable for me if there was a tag. (Since you can clone tags/branches directly, something you can't do for commit hashes.) Right now it seems the code works quite fine, so maybe a 1.0.0 release is in order?

need for char** array type and function callbacks

Hi Cofyc. Some time ago I forked argparse for a personal need.
I added the capability to call a function associated with an argument and a new type ARGPARSE_OPT_ARRAY that works and allocate char ** .

My fork can be found here:
https://github.com/FraMecca/libargparse

and this is the fork in action:
http://francescomecca.eu:3000/pesceWanda/kpd/src/development/src/main.c

If you want and if it is needed, we can work to merge my code to your original work

Let me know if interested.

Francesco

Support for default int/float/string values?

Thanks for a great library!

I was just wondering, how could I implement default values easily?

That is, if --myoption argument is not specified on the command line, then, say, the corresponding float myoption in C code gets the value (for example) 5.0 ...

I have seen in the code https://github.com/cofyc/argparse/blob/master/argparse.h, the last three arguments to the macros are:

 *  `callback`:
 *    function is called when corresponding argument is parsed.
 *
 *  `data`:
 *    associated data. Callbacks can use it like they want.
 *
 *  `flags`:
 *    option flags.

So, I guess, I'd have to implement a custom callback for all such options, and then assign data in the callback, in case the command line argument was not found on the command line. But then, I'm not sure how could I check in the callback, whether the command line argument was present or not?

Is there an example that shows such usage (with default values for arguments, if they are not set on the command line)?

Unclear and untested callback feature

There is a callback which returns an int value. How is this handled? Does it override the value assignment for integers?

I assume the intptr_t field in options is used to pass a value to it, but that value is limited to 32-bits on x86 but 64-bits on amd64. Did you intend to make this architecture-dependent? Why not void*?

Default value for arguments without parameter

Hi! Could a flag be used with parameter and without parameter simultaneously?

For example smth like:
#define INT_DEFAULT_VALUE 10
OPT_BOOLEAN('f', "force", &force, "force to do", NULL, 0, 0),
OPT_INTEGER('i', "int", &int_num, "selected integer", NULL, 0, 0), //some way to transfer INT_DEFAULT_VALUE inside parser

my cmd -i 15 -f

force: 1
int_num: 15

Now it outputs next string:
my cmd -i -f

[int_num: 15](error: option -i expects an integer value)

But could the parameter be used with a default value like this:
my cmd -i -f

force: 1
int_num: 10

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.