LordOfTrident / cargs

A command line arguments parsing library for C

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

!This project has been moved to chol!

cargs

License Issues GitHub pull requests


A simple single-header STB-style C library for parsing command line arguments and flags (similar to Golang's flag package).

Table of contents

Simple example

#include <stdio.h>

#define CARGS_IMPLEMENTATION
#include "cargs.h"

int main(int argc, const char **argv) {
	args_t a = new_args(argc, argv);
	const char *app_name = args_shift(&a);

	bool help = false;
	flag_bool("h", "help", "Show the usage", &help);

	args_parse_flags(&a, NULL, NULL);
	if (help) {
		args_print_usage(stdout, app_name, "[OPTIONS]");
		return 0;
	}

	printf("Hello, world!\n");

	return 0;
}

Output

Quickstart

Since cargs is a single-header library, you can just copy cargs.h into your project and include it, or submodule this repository and include the header. See the example to see how to use the library.

To compile and run the example, run

$ cc ./examples/size.c -o size
$ ./size -h

Bugs

If you find any bugs, please create an issue and report them.

About

A command line arguments parsing library for C

License:GNU General Public License v3.0


Languages

Language:C 100.0%