Ballad follows a simple pattern and attempts to abstract away all the unnecessary complexity involved in the creation of tools so the developer can focus on creating their own software.
Ballad is extremely easy to setup and all you need to do to get started is to add the ballad.h file which you can obtain from the Ballad Github repository. You can either clone the repo or download it and copy the .h into your project directory to use.
git clone https://github.com/lordryns/ballad.git
Using Ballad is extremely simple, import it directly into your program to get started
#define BALLARD_IMPLEMENTATION
#include "ballad.h"
After this, you can then initialize the cli inside your main function by using the ballad_init function and start it using the ballad_run function
int main(int charc, char **charv)
{
BalladCli cli = ballad_init(charc, charv, "Create fun stuff with test-cli");
ballad_run(cli); // important: the cli will not start if this is omitted
return 0;
}
That's it! You can now compile your code and see the output
clang main.c -o test-cli && ./test-cli // or use gcc if you want
Your program should compile successfully and the output should be like this
Usage: ./test-cli COMMAND [OPTIONS] [ARGS]
Create fun stuff with test-cli
Options:
--help, -h Show this message and exit.
Commands:
Your code works as intended but You have not defined any valid commands yet, in order to do that You'd need to use the ballad_add_command function
ballad_add_command(&cli, (BalladCommand){"new", "Create a new project", create_new_project});
In case it wasn't obvious ballad_add_command takes two arguments, a pointer to the BallardCli and a BallardCommand struct which in turn takes three arguments which include the command name, help and the function to be executed. Full code would look like this:
#include
#define BALLAD_IMPLEMENTATION
#include "ballad.h"
void create_new_project(char *arg)
{
printf("Your project '%s' created successfully!\n", arg);
}
int main(int charc, char **charv)
{
BalladCli cli = ballad_init(charc, charv, "Create fun stuff with test-cli");
ballad_add_command(&cli, (BalladCommand){"new", "Create a new project", create_new_project});
ballad_run(cli);
return 0;
}
Links: Go to Main Projects