Move print helper functions to arg_parse.h

These functions have more to do with commands, and it will be more
helpful to have the print_help function especially in the same file as
the actual commands structure.
This commit is contained in:
Nicolás A. Ortega Froysa 2024-09-19 18:36:43 +02:00
parent 9bc45d634e
commit cf1a40c2fe
2 changed files with 21 additions and 18 deletions

View File

@ -17,6 +17,8 @@
*/ */
#pragma once #pragma once
#include <stdio.h>
enum cmd_id { enum cmd_id {
CMD_UNKNOWN = 0, CMD_UNKNOWN = 0,
CMD_HELP, CMD_HELP,
@ -33,4 +35,23 @@ static const struct cmd commands[] = {
{ CMD_VERSION, {"version", "-v", "--version"} }, { CMD_VERSION, {"version", "-v", "--version"} },
}; };
static inline void print_version(void) {
printf("menu-helper v%s\n\n", VERSION);
}
static inline void print_usage(void) {
printf("USAGE: menu-helper <cmd> [options]\n\n");
}
static inline void print_help(void) {
print_version();
print_usage();
printf("COMMANDS:\n"
"\thelp, -h, --help Show this help information.\n"
"\tversion, -v, --version Show version information.\n"
"\n");
}
enum cmd_id parse_args(const char *cmd); enum cmd_id parse_args(const char *cmd);

View File

@ -20,24 +20,6 @@
#include "arg_parse.h" #include "arg_parse.h"
void print_version(void) {
printf("menu-helper v%s\n\n", VERSION);
}
void print_usage(void) {
printf("USAGE: menu-helper <cmd> [options]\n\n");
}
void print_help(void) {
print_version();
print_usage();
printf("COMMANDS:\n"
"\thelp, -h, --help Show this help information.\n"
"\tversion, -v, --version Show version information.\n"
"\n");
}
int main(int argc, char *argv[]) { int main(int argc, char *argv[]) {
enum cmd_id id; enum cmd_id id;