Added support for commands
This commit is contained in:
parent
9cd9ca03af
commit
ba07fd7968
@ -9,3 +9,20 @@
|
|||||||
int main(int argc, char* argv[]) {
|
int main(int argc, char* argv[]) {
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Command* find_command(const char* name) {
|
||||||
|
Command* match = NULL;
|
||||||
|
|
||||||
|
// Find all matching commands (starting with the given name)
|
||||||
|
size_t length = strlen(name);
|
||||||
|
for (size_t i = 0; i < sizeof(COMMANDS) / sizeof(COMMANDS[0]); i++)
|
||||||
|
if (strncmp(name, COMMANDS[i].name, length) == 0) {
|
||||||
|
// Check for multiple matches
|
||||||
|
if (match != NULL)
|
||||||
|
return NULL;
|
||||||
|
|
||||||
|
match = &COMMANDS[i];
|
||||||
|
}
|
||||||
|
|
||||||
|
return match;
|
||||||
|
}
|
||||||
|
@ -1,3 +1,36 @@
|
|||||||
#pragma once
|
#pragma once
|
||||||
|
|
||||||
|
#include <stdlib.h>
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char* name;
|
||||||
|
const char* args;
|
||||||
|
const char* description;
|
||||||
|
} Command;
|
||||||
|
|
||||||
|
Command COMMANDS[] = {
|
||||||
|
{"help", "[command]", "Shows help for all or a specific command."},
|
||||||
|
{"version", NULL, "Shows the version of the program."},
|
||||||
|
{NULL, NULL, NULL},
|
||||||
|
{"add-entry", "<entry> [--root|-r <size>] [--backing|-b <backing>]", "Adds a new entry to the pool"},
|
||||||
|
{"remove-entry", "<entry>", "Removes an entry from the pool"},
|
||||||
|
{"list-entries", NULL, "Lists all entries in the pool"},
|
||||||
|
{"clear-entries", NULL, "Clears all entries from the pool"},
|
||||||
|
{NULL, NULL, NULL},
|
||||||
|
{"add-backing", "<entry>", "Adds a backing disk to the pool from the given entry"},
|
||||||
|
{"remove-backing", "<backing>", "Removes a backing disk from the pool"},
|
||||||
|
{"list-backings", "[--tree|-t]", "Lists all backing disks in the pool"},
|
||||||
|
{"clear-backings", NULL, "Clears all backing disks from the pool"},
|
||||||
|
{NULL, NULL, NULL},
|
||||||
|
{"start", "<entry> [--no-pci] [--vnc <port> <password>] [--iso <iso>]", "Starts the sandbox with the given entry"},
|
||||||
|
{"power", NULL, "Sends a power signal to the sandbox"},
|
||||||
|
{"stop", "[--force|-f] [--timeout|-t <timeout>]", "Stops the sandbox"},
|
||||||
|
{"status", NULL, "Shows the status of the sandbox"},
|
||||||
|
};
|
||||||
|
|
||||||
int main(int argc, char* argv[]);
|
int main(int argc, char* argv[]);
|
||||||
|
|
||||||
|
/// @brief Finds the best matching command for the given command name.
|
||||||
|
/// @param name The name of the command to find.
|
||||||
|
/// @return The best matching command or NULL if no or multiple matches were found. No need to free the result.
|
||||||
|
Command* find_command(const char* name);
|
||||||
|
Loading…
Reference in New Issue
Block a user