ZClk  0.1.0-alpha.3
Library to build cli programs
ZClk Documentation

NOTE: This library is still under development. The public API is unstable till the library reaches beta status. There will be breaking changes in public API if needed.

ZClk is a C library to build command line interfaces aka CLI programs.

Getting Started

Build the package using CMake

The Makefile in the source folder contains targets for useful CMake commands. You can use the genbuild and build targets to create the CMake build folder, and then run the build for your platform.

$ make genbuild build

Use the library in your code.

A library named zclk (with appropriate prefix/suffix for your platform) will be generated in the ./build folder.

Use this library and add the src folder to your include folders during compilation.

Simple Example

The zclk_command struct and its associated functions provide the majority of the public api of the library. There are functions to create commands, add options and arguments and then execute the commands given the program arguments. These are all demostrated in sample programs in the ./samples folder in the source code.

Here is a simple implementation with one command which has one option and one argument - to give a feel of the API...

#include <zclk.h>
#include <stdio.h>
zclk_res basic_handler(zclk_command* cmd, void* handler_args)
{
printf("Sample#1: Basic Usage of CLIUTILS with "
"One Argument and One Option.\n");
printf("\n** Options\n");
{
printf("\toption: %s=%d\n", opt->name, zclk_option_get_val_flag(opt));
}
printf("\n** Arguments\n");
{
printf("\targument: %s=%s\n", argument->name, zclk_argument_get_val_string(argument));
}
return 0;
}
int main(int argc, char* argv[])
{
zclk_command *cmd = new_zclk_command(argv[0], "cmd",
"Basic Description", &basic_handler);
cmd,
"option-one",
"o",
"Option One"
);
cmd,
"arg-one",
"blah",
"Argument One",
1
);
zclk_command_exec(cmd, NULL, argc, argv);
}
A CLI Command Ojbect.
Definition: zclk.h:388
Zclk main header file. Defines the Public API of zclk.
MODULE_API void zclk_command_flag_option(zclk_command *cmd, const char *name, const char *short_name, const char *desc)
Create a new flag option and add it to the given command.
Definition: zclk.c:919
MODULE_API void zclk_command_string_argument(zclk_command *cmd, const char *name, const char *default_val, const char *desc, int nargs)
Create a new bool argument and add it to the given command.
Definition: zclk.c:967
MODULE_API zclk_command * new_zclk_command(const char *name, const char *short_name, const char *description, zclk_command_fn handler)
Create a command object with automatic error handling.
Definition: zclk.c:819
MODULE_API zclk_res zclk_command_exec(zclk_command *cmd, void *exec_args, int argc, char *argv[])
Execute the command with the given args.
Definition: zclk.c:1027
zclk_res
This enum defines the possible error codes generated by functions in the API.
Definition: zclk.h:39
#define zclk_command_argument_foreach(cmd, arg)
Iterator for arguments of the given command.
Definition: zclk.h:821
#define zclk_command_option_foreach(cmd, opt)
Iterator for options of the given command.
Definition: zclk.h:805

Public API Header

The public API of the library is provided by zclk.h.