Added support for command details
This commit is contained in:
parent
2c0dd8d9ab
commit
d925445876
@ -6,23 +6,23 @@
|
|||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
Command COMMANDS[] = {
|
Command COMMANDS[] = {
|
||||||
{"help", "[command]", "Shows help for all or a specific command.", CMD_HELP},
|
{CMD_HELP, "help", "[command]", "Shows help for all or a specific command.", "TODO"},
|
||||||
{"version", "", "Shows the version of the program.", CMD_VERSION},
|
{CMD_VERSION, "version", "", "Shows the version of the program.", "TODO"},
|
||||||
{NULL},
|
{CMD_SEPARATOR},
|
||||||
{"add-entry", "<entry> [--root|-r <size>] [--backing|-b <backing>]", "Adds a new entry to the pool", CMD_ADD_ENTRY},
|
{CMD_ADD_ENTRY, "add-entry", "<entry> [--root|-r <size>] [--backing|-b <backing>]", "Adds a new entry to the pool", "TODO"},
|
||||||
{"remove-entry", "<entry>", "Removes an entry from the pool", CMD_REMOVE_ENTRY},
|
{CMD_REMOVE_ENTRY, "remove-entry", "<entry>", "Removes an entry from the pool", "TODO"},
|
||||||
{"list-entries", "", "Lists all entries in the pool", CMD_LIST_ENTRIES},
|
{CMD_LIST_ENTRIES, "list-entries", "", "Lists all entries in the pool", "TODO"},
|
||||||
{"clear-entries", "", "Clears all entries from the pool", CMD_CLEAR_ENTRIES},
|
{CMD_CLEAR_ENTRIES, "clear-entries", "", "Clears all entries from the pool", "TODO"},
|
||||||
{NULL},
|
{CMD_SEPARATOR},
|
||||||
{"add-backing", "<entry>", "Adds a backing disk to the pool from the given entry", CMD_ADD_BACKING},
|
{CMD_ADD_BACKING, "add-backing", "<entry>", "Adds a backing disk to the pool from the given entry", "TODO"},
|
||||||
{"remove-backing", "<backing>", "Removes a backing disk from the pool", CMD_REMOVE_BACKING},
|
{CMD_REMOVE_BACKING, "remove-backing", "<backing>", "Removes a backing disk from the pool", "TODO"},
|
||||||
{"list-backings", "[--tree|-t]", "Lists all backing disks in the pool", CMD_LIST_BACKINGS},
|
{CMD_LIST_BACKINGS, "list-backings", "[--tree|-t]", "Lists all backing disks in the pool", "TODO"},
|
||||||
{"clear-backings", "", "Clears all backing disks from the pool", CMD_CLEAR_BACKINGS},
|
{CMD_CLEAR_BACKINGS, "clear-backings", "", "Clears all backing disks from the pool", "TODO"},
|
||||||
{NULL},
|
{CMD_SEPARATOR},
|
||||||
{"start", "<entry> [--no-pci] [--vnc <port> <password>] [--iso <iso>]", "Starts the sandbox with the given entry", CMD_START},
|
{CMD_START, "start", "<entry> [--no-pci] [--vnc <port> <password>] [--iso <iso>]", "Starts the sandbox with the given entry", "TODO"},
|
||||||
{"power", "", "Sends a power signal to the sandbox", CMD_POWER},
|
{CMD_POWER, "power", "", "Sends a power signal to the sandbox", "TODO"},
|
||||||
{"stop", "[--force|-f] [--timeout|-t <timeout>]", "Stops the sandbox", CMD_STOP},
|
{CMD_STOP, "stop", "[--force|-f] [--timeout|-t <timeout>]", "Stops the sandbox", "TODO"},
|
||||||
{"status", "", "Shows the status of the sandbox", CMD_STATUS},
|
{CMD_STATUS, "status", "", "Shows the status of the sandbox", "TODO"},
|
||||||
};
|
};
|
||||||
|
|
||||||
Command* find_command(const char* name) {
|
Command* find_command(const char* name) {
|
||||||
@ -54,7 +54,7 @@ void show_help() {
|
|||||||
printf("Usage: sandbox <command> [args]\n\n");
|
printf("Usage: sandbox <command> [args]\n\n");
|
||||||
printf("Commands:\n");
|
printf("Commands:\n");
|
||||||
for (size_t i = 0; i < sizeof(COMMANDS) / sizeof(COMMANDS[0]); i++) {
|
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");
|
printf("\n");
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
@ -69,6 +69,11 @@ void show_help() {
|
|||||||
void show_command_help(const Command* command) {
|
void show_command_help(const Command* command) {
|
||||||
printf("Usage: sandbox %s %s\n", command->name, command->args);
|
printf("Usage: sandbox %s %s\n", command->name, command->args);
|
||||||
printf(" %s\n", command->description);
|
printf(" %s\n", command->description);
|
||||||
|
|
||||||
|
if (command->details != NULL) {
|
||||||
|
printf("\n");
|
||||||
|
printf("%s\n", command->details);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int cmd_help(int argc, char** argv) {
|
int cmd_help(int argc, char** argv) {
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
typedef enum {
|
typedef enum {
|
||||||
CMD_UNKNOWN,
|
CMD_UNKNOWN,
|
||||||
|
CMD_SEPARATOR,
|
||||||
|
|
||||||
CMD_HELP,
|
CMD_HELP,
|
||||||
CMD_VERSION,
|
CMD_VERSION,
|
||||||
@ -25,10 +26,11 @@ typedef enum {
|
|||||||
} CommandID;
|
} CommandID;
|
||||||
|
|
||||||
typedef struct {
|
typedef struct {
|
||||||
|
CommandID id;
|
||||||
const char* name;
|
const char* name;
|
||||||
const char* args;
|
const char* args;
|
||||||
const char* description;
|
const char* description;
|
||||||
CommandID id;
|
const char* details;
|
||||||
} Command;
|
} Command;
|
||||||
|
|
||||||
extern Command COMMANDS[];
|
extern Command COMMANDS[];
|
||||||
|
@ -25,6 +25,7 @@ int main(int argc, char* argv[]) {
|
|||||||
return cmd_help(argc - 2, argv + 2);
|
return cmd_help(argc - 2, argv + 2);
|
||||||
case CMD_VERSION:
|
case CMD_VERSION:
|
||||||
return cmd_version(argc - 2, argv + 2);
|
return cmd_version(argc - 2, argv + 2);
|
||||||
|
|
||||||
default:
|
default:
|
||||||
log_message(LOG_ERROR, "Command '%s' is not implemented.", command->name);
|
log_message(LOG_ERROR, "Command '%s' is not implemented.", command->name);
|
||||||
break;
|
break;
|
||||||
|
Loading…
Reference in New Issue
Block a user