From d92544587670643a73dcc3536d108ce732ba3bd6 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Alexe=C3=AF=20KADIR?= Date: Fri, 16 Feb 2024 17:19:56 +0100 Subject: [PATCH] Added support for command details --- src/command.c | 41 +++++++++++++++++++++++------------------ src/command.h | 4 +++- src/sandbox.c | 1 + 3 files changed, 27 insertions(+), 19 deletions(-) diff --git a/src/command.c b/src/command.c index ed5688a..35b9abc 100644 --- a/src/command.c +++ b/src/command.c @@ -6,23 +6,23 @@ #include Command COMMANDS[] = { - {"help", "[command]", "Shows help for all or a specific command.", CMD_HELP}, - {"version", "", "Shows the version of the program.", CMD_VERSION}, - {NULL}, - {"add-entry", " [--root|-r ] [--backing|-b ]", "Adds a new entry to the pool", CMD_ADD_ENTRY}, - {"remove-entry", "", "Removes an entry from the pool", CMD_REMOVE_ENTRY}, - {"list-entries", "", "Lists all entries in the pool", CMD_LIST_ENTRIES}, - {"clear-entries", "", "Clears all entries from the pool", CMD_CLEAR_ENTRIES}, - {NULL}, - {"add-backing", "", "Adds a backing disk to the pool from the given entry", CMD_ADD_BACKING}, - {"remove-backing", "", "Removes a backing disk from the pool", CMD_REMOVE_BACKING}, - {"list-backings", "[--tree|-t]", "Lists all backing disks in the pool", CMD_LIST_BACKINGS}, - {"clear-backings", "", "Clears all backing disks from the pool", CMD_CLEAR_BACKINGS}, - {NULL}, - {"start", " [--no-pci] [--vnc ] [--iso ]", "Starts the sandbox with the given entry", CMD_START}, - {"power", "", "Sends a power signal to the sandbox", CMD_POWER}, - {"stop", "[--force|-f] [--timeout|-t ]", "Stops the sandbox", CMD_STOP}, - {"status", "", "Shows the status of the sandbox", CMD_STATUS}, + {CMD_HELP, "help", "[command]", "Shows help for all or a specific command.", "TODO"}, + {CMD_VERSION, "version", "", "Shows the version of the program.", "TODO"}, + {CMD_SEPARATOR}, + {CMD_ADD_ENTRY, "add-entry", " [--root|-r ] [--backing|-b ]", "Adds a new entry to the pool", "TODO"}, + {CMD_REMOVE_ENTRY, "remove-entry", "", "Removes an entry from the pool", "TODO"}, + {CMD_LIST_ENTRIES, "list-entries", "", "Lists all entries in the pool", "TODO"}, + {CMD_CLEAR_ENTRIES, "clear-entries", "", "Clears all entries from the pool", "TODO"}, + {CMD_SEPARATOR}, + {CMD_ADD_BACKING, "add-backing", "", "Adds a backing disk to the pool from the given entry", "TODO"}, + {CMD_REMOVE_BACKING, "remove-backing", "", "Removes a backing disk from the pool", "TODO"}, + {CMD_LIST_BACKINGS, "list-backings", "[--tree|-t]", "Lists all backing disks in the pool", "TODO"}, + {CMD_CLEAR_BACKINGS, "clear-backings", "", "Clears all backing disks from the pool", "TODO"}, + {CMD_SEPARATOR}, + {CMD_START, "start", " [--no-pci] [--vnc ] [--iso ]", "Starts the sandbox with the given entry", "TODO"}, + {CMD_POWER, "power", "", "Sends a power signal to the sandbox", "TODO"}, + {CMD_STOP, "stop", "[--force|-f] [--timeout|-t ]", "Stops the sandbox", "TODO"}, + {CMD_STATUS, "status", "", "Shows the status of the sandbox", "TODO"}, }; Command* find_command(const char* name) { @@ -54,7 +54,7 @@ void show_help() { printf("Usage: sandbox [args]\n\n"); printf("Commands:\n"); for (size_t i = 0; i < sizeof(COMMANDS) / sizeof(COMMANDS[0]); i++) { - if (COMMANDS[i].name == NULL) { + if (COMMANDS[i].id == CMD_SEPARATOR) { printf("\n"); continue; } @@ -69,6 +69,11 @@ void show_help() { void show_command_help(const Command* command) { printf("Usage: sandbox %s %s\n", command->name, command->args); printf(" %s\n", command->description); + + if (command->details != NULL) { + printf("\n"); + printf("%s\n", command->details); + } } int cmd_help(int argc, char** argv) { diff --git a/src/command.h b/src/command.h index a164047..7f83c74 100644 --- a/src/command.h +++ b/src/command.h @@ -4,6 +4,7 @@ typedef enum { CMD_UNKNOWN, + CMD_SEPARATOR, CMD_HELP, CMD_VERSION, @@ -25,10 +26,11 @@ typedef enum { } CommandID; typedef struct { + CommandID id; const char* name; const char* args; const char* description; - CommandID id; + const char* details; } Command; extern Command COMMANDS[]; diff --git a/src/sandbox.c b/src/sandbox.c index 854fd10..6dfe6c7 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -25,6 +25,7 @@ int main(int argc, char* argv[]) { return cmd_help(argc - 2, argv + 2); case CMD_VERSION: return cmd_version(argc - 2, argv + 2); + default: log_message(LOG_ERROR, "Command '%s' is not implemented.", command->name); break;