argparse
argparse copied to clipboard
improve subcommands, convert tests from tap to pytest, improve examples
Subcommands
Subcommands are now easier to add. up until now matching subcommands was done in subcommands.c
- requiring users to handle it in their own codebase. It is now taken care of inside of argparse_parse
instead. Adding subcommands is also easier via the CMD
macro.
Pytest for Tests
Previous testing was done in TAP which is a language agnostic testing thing. This is not very maintainable as perl is getting out of use.
I've switch to python as its 1000% more popular and has great testing abilities. I've also added tests. If you have ideas for more tests let me know.
Examples Change
basic.c
hasn't changed too much. I've mostly changed its output to fit json format in to easily test it and allow future testing in ease. Some macros were fully initialized with zeros and nulls I've removed because examples must be simple. In C structs which are "partially initialized" have their non explicitly set members set to zero which is the same.
subcommands.c
was changed in a few ways. mainly changing names from foo
and bar
because they are not indicative and make it less clear to understand. I've also made use of the changes I've added to subcommands as a whole.
Note
I was trying to conform to python3's click
package as its the best way of achieving argparse in means of conforming to standards. Running an argparsed program without arguments result and printing the usages however adding no parameters but the --
sign will not show usages.
Tell me your thoughts if you prefer a different flow and if so why.
[APPROVALNOTIFIER] This PR is NOT APPROVED
This pull-request has been approved by: aBraM-aBraM
To complete the pull request process, please assign cofyc
You can assign the PR to them by writing /assign @cofyc
in a comment when ready.
The full list of commands accepted by this bot can be found here.
Approvers can indicate their approval by writing /approve
in a comment
Approvers can cancel approval by writing /approve cancel
in a comment
/assign @cofyc