Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/mebiusashan/ccli
Command-line arguments parsing library.
https://github.com/mebiusashan/ccli
c ccli cli
Last synced: about 2 months ago
JSON representation
Command-line arguments parsing library.
- Host: GitHub
- URL: https://github.com/mebiusashan/ccli
- Owner: mebiusashan
- License: bsd-3-clause
- Created: 2021-01-25T08:48:49.000Z (almost 4 years ago)
- Default Branch: main
- Last Pushed: 2021-02-01T10:36:11.000Z (almost 4 years ago)
- Last Synced: 2024-11-21T05:02:15.495Z (about 2 months ago)
- Topics: c, ccli, cli
- Language: C
- Homepage:
- Size: 40 KB
- Stars: 1
- Watchers: 3
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
# ccli
ccli - A command line arguments parsing library in C (compatible with C++).
## Description
This module is inspired by argparse.
Arguments parsing is common task in cli program, but traditional `getopt`
libraries are not easy to use. This library provides high-level arguments
parsing solutions.The program defines what arguments it requires, and `argparse` will figure
out how to parse those out of `argc` and `argv`, it also automatically
generates help and usage messages and issues errors when users give the
program invalid arguments.## Features
- handles both optional and positional arguments
- produces highly informative usage messages
- issues errors when given invalid arguments
- support subcommandThere are basically three types of options:
- boolean options
- options with mandatory argument
- options with optional argumentThere are basically two forms of options:
- short option consist of one dash (`-`) and one alphanumeric character.
- long option begin with two dashes (`--`) and some alphanumeric characters.Short options may be bundled, e.g. `-a -b` can be specified as `-ab`.
Options are case-sensitive.
Options and non-option arguments can clearly be separated using the `--` option.
## Examples
```c
#include
#include "ccli.h"int force =0;
int abc = 0;
float cc = 0;
char * ss = "";int rootRun ( int argc, const char **argv )
{
printf ( "%d - %d - %f - %s \n", force, abc, cc, ss );
printf ( "%d\n",argc );
for ( int i=0; i num option.
-w, --width width option.
-d, --des description option.
-h, --help print help message.epilog string
``````
$ ./ccli -n5
0 - 5 - 0.000000 -
0
``````
$ ./ccli -f -d="this is des."
1 - 0 - 0.000000 - this is des.
0
```