Skip to content
/ cargs Public
forked from LordOfTrident/cargs

A command line arguments parsing library for C

License

Notifications You must be signed in to change notification settings

yeti0904/cargs

 
 

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

14 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

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

Resources

License

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages

  • C 100.0%