2023-07-13 20:42:37 +02:00
2023-06-20 12:11:29 +02:00
2023-06-12 15:38:07 +02:00
2023-07-13 20:42:37 +02:00
2023-06-12 15:38:07 +02:00
2023-06-23 21:50:15 +02:00
2023-06-20 14:01:51 +02:00
2023-06-23 21:50:40 +02:00

Setopt

The reverse of getopt. It is standard to create a command from an internal state (object). It is a replacement for usual string concatenation techniques, providing argument order consistency and less bug-prone error handling.

Docs

C

Implemented as a header only library.

#include "setopt.h"

/* Struct to define long option - identifier pairs + flags;
	Straight from getopt
*/
struct option {
	const char *name;
	int         has_arg;
	int        *flag;
	int         val;
};

int optc,		// number of arguments successfuly added
					reset on each invocation
	optred,		/* not implemented */
	opterrno;	// non zero if setopt encountered an error
					must be reset manually

char* setopt(const char* optstring, std::unordered_map<char, std::string> argv);
char* setopt_long(char* optstring, map<string, string> argv, map<string, string> argv_long);    /* Not implemented */
char* setopt_long_only(char* optstring, map<string, string> argv_long);                         /* Not implemented */

optstring: Complies with GNU getopt's optstring. That is: optstring is a string containing the legitimate option characters. A legitimate option character is any visible one byte ascii(7) character (for which isgraph(3) would return nonzero) that is not '-', ':', or ';'. If such a character is followed by a colon, the option requires an argument [...] Two colons mean an option takes an optional arg [...]

Cli

setopt <options>  :
		-s <str>  : specify optstring
		-j <json> : read arguments from JSON string
		-h        : print help message and quit

Commandline interface to the setopt functions. The current most useful feature us to use a JSON object to generate flags.

Description
No description provided
Readme 171 KiB
Languages
C++ 99.9%