Go to the documentation of this file.
6 #include "../../include/utils/colors.h"
7 #include "../../include/utils/command_line.h"
8 #include "../../include/utils/array_len.h"
9 #include "../../include/utils/logger.h"
10 #include "../../include/utils/safe_mem.h"
26 printf(
"failed to malloc command_object\n");
34 for (
int i = 0; i < argc; i++) {
35 pcobj->
argv[i] = malloc(strlen(argv[i]) + 1);
36 if (pcobj->
argv[i] == NULL) {
37 printf(
"failed to malloc argv space\n");
40 strcpy(pcobj->
argv[i], argv[i]);
52 int n =
self->command_count++;
60 for (
int i = 0; i <
self->command_count; i++) {
61 if (strcmp(self->commands[i]->name, run) == 0) {
62 self->commands[i]->callback(self->argc, self->argv);
75 for (
int i = 0; i <
self->command_count; i++) {
76 free(self->commands[i]);
82 int parse_args(
int argc,
char *argv[],
void *argtable[]) {
83 if (arg_nullcheck(argtable) != 0) {
86 int nerrors = arg_parse(argc, argv, argtable);
88 if (
help->count > 0) {
93 arg_print_errors(stdout,
end,
"main");
100 printf(
"Usage: %s", program_name);
101 arg_print_syntax(stdout, argtable,
"\n");
102 arg_print_glossary(stdout, argtable,
" %-25s %s\n");
107 help = arg_litn(NULL,
"help", 0, 1,
"displays help menu");
108 version = arg_litn(NULL,
"version", 0, 1, version_string);
109 file = arg_filen(NULL,
"file",
"<file>", 0, 10,
"file(s) to load data from max of 10");
110 output = arg_filen(NULL,
"output",
"<file>", 0, 1,
"file to output data too");
111 command_to_run = arg_strn(
"c",
"command",
"<command>", 0, 1,
"command to run");
117 if (run_command == NULL) {
118 printf(
"failed to malloc run_command\n");
struct arg_str * command_to_run
void print_help(char *program_name, void *argtable[])
formats output
int parse_args(int argc, char *argv[], void *argtable[])
parses arguments, and checks for any errors
void free_command_object(command_object *self)
frees memory allocated for the command_object and sets pointer to null for some reason this is causin...
int load_command(command_object *self, command_handler *command)
loads command handler and makes it executable
void setup_args(const char *version_string)
setups the default argtable arguments
int execute(command_object *self, char *run)
checks to see if we have a command named according to run and executes it
char * get_run_command()
returns the value of command_to_run
command_object * new_command_object(int argc, char *argv[])
intializes a new command_object to have commands loaded into
void print_colored(COLORS color, char *message)
prints message to stdout with the given color