Added some commands

This commit is contained in:
Alexei KADIR 2024-02-18 00:07:44 +01:00
parent 487982a182
commit 0aa2cfbfa8
2 changed files with 70 additions and 6 deletions

View File

@ -14,6 +14,15 @@ Command COMMANDS[] = {
"TODO: Add details."},
{CommandVersion, "version", NULL, "Prints the version of the program.",
"TODO: Add details."},
{},
{CommandAddEntry, "add-entry", "<entry id>", "Adds a new entry to the sandbox.",
"TODO: Add details."},
{CommandRemoveEntry, "remove-entry", "<entry id>", "Removes an entry from the sandbox.",
"TODO: Add details."},
{CommandListEntries, "list-entries", NULL, "Lists all the entries in the sandbox.",
"TODO: Add details."},
{CommandClearEntries, "clear-entries", NULL, "Clears all the entries from the sandbox.",
"TODO: Add details."},
};
int main(int argc, char* argv[]) {
@ -106,11 +115,7 @@ int CommandHelp(int argc, char* argv[]) {
fprintf(stdout, "Usage: sandbox %s", COMMANDS[i].name);
if (COMMANDS[i].arguments != NULL)
fprintf(stdout, " %s", COMMANDS[i].arguments);
fprintf(stdout, "\n");
fprintf(stdout, "\n");
fprintf(stdout, "%s\n", COMMANDS[i].description);
fprintf(stdout, "\n");
fprintf(stdout, "%s\n", COMMANDS[i].details);
fprintf(stdout, "\n %s\n\n %s\n", COMMANDS[i].description, COMMANDS[i].details);
return EXIT_SUCCESS;
}
@ -130,3 +135,57 @@ int CommandVersion(int argc, char* argv[]) {
fprintf(stdout, "Sandbox utility v%s\n", VERSION);
return EXIT_SUCCESS;
}
int CommandAddEntry(int argc, char* argv[]) {
if (argc < 1) {
Log(LOG_LEVEL_ERROR, "Too few arguments supplied to 'add-entry'.");
return EXIT_FAILURE;
} else if (argc > 1) {
Log(LOG_LEVEL_ERROR, "Too many arguments supplied to 'add-entry'.");
return EXIT_FAILURE;
}
return AddEntry(argv[0]);
}
int CommandRemoveEntry(int argc, char* argv[]) {
if (argc < 1) {
Log(LOG_LEVEL_ERROR, "Too few arguments supplied to 'remove-entry'.");
return EXIT_FAILURE;
} else if (argc > 1) {
Log(LOG_LEVEL_ERROR, "Too many arguments supplied to 'remove-entry'.");
return EXIT_FAILURE;
}
return RemoveEntry(argv[0]);
}
int CommandListEntries(int argc, char* argv[]) {
if (argc > 0) {
Log(LOG_LEVEL_ERROR, "Too many arguments supplied to 'list-entries'.");
return EXIT_FAILURE;
}
char** entries = NULL;
Status status = ListEntries(&entries);
if (status != SUCCESS)
return status;
for (size_t i = 0; entries[i] != NULL; i++)
fprintf(stdout, "%s\n", entries[i]);
for (size_t i = 0; entries[i] != NULL; i++)
free(entries[i]);
free(entries);
return EXIT_SUCCESS;
}
int CommandClearEntries(int argc, char* argv[]) {
if (argc > 0) {
Log(LOG_LEVEL_ERROR, "Too many arguments supplied to 'clear-entries'.");
return EXIT_FAILURE;
}
return ClearEntries();
}

View File

@ -16,3 +16,8 @@ int main(int argc, char* argv[]);
int CommandHelp(int argc, char* argv[]);
int CommandVersion(int argc, char* argv[]);
int CommandAddEntry(int argc, char* argv[]);
int CommandRemoveEntry(int argc, char* argv[]);
int CommandListEntries(int argc, char* argv[]);
int CommandClearEntries(int argc, char* argv[]);