diff --git a/src/sandbox.c b/src/sandbox.c index 5fbf797..26c4dc8 100644 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -14,6 +14,15 @@ Command COMMANDS[] = { "TODO: Add details."}, {CommandVersion, "version", NULL, "Prints the version of the program.", "TODO: Add details."}, + {}, + {CommandAddEntry, "add-entry", "", "Adds a new entry to the sandbox.", + "TODO: Add details."}, + {CommandRemoveEntry, "remove-entry", "", "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(); +} diff --git a/src/sandbox.h b/src/sandbox.h index 510a9bd..954250a 100644 --- a/src/sandbox.h +++ b/src/sandbox.h @@ -15,4 +15,9 @@ typedef struct { int main(int argc, char* argv[]); int CommandHelp(int argc, char* argv[]); -int CommandVersion(int argc, char* argv[]); \ No newline at end of file +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[]); \ No newline at end of file