From e6ac4a3e91f0c26ff999b92120fb61dec727c067 Mon Sep 17 00:00:00 2001 From: Adrien Bourmault Date: Wed, 23 Jun 2021 21:44:51 +0200 Subject: [PATCH] cli model command (create) --- src/cmds.c | 86 +++++++++++++++++++++++++++++++++++++++++++++++------- 1 file changed, 76 insertions(+), 10 deletions(-) diff --git a/src/cmds.c b/src/cmds.c index 0e11406..9230b8b 100644 --- a/src/cmds.c +++ b/src/cmds.c @@ -36,29 +36,97 @@ char *CmdHelp(char **argv, Server_t *args) char *CmdModel(char **argv, Server_t *args) { char *buf; + char temp[255]; + int tempsize; + Model_t *newModel; + buf = (char *) calloc(LINE_NUMBER, LINE_LENGTH * sizeof(char)); + // invalid use if (!argv[1]) { - strcat(buf, "{create | delete | load | run}\n"); + strcat(buf, "{create | delete | load | run | list | info}\n"); goto CmdModelEnd; } if (strcmp(argv[1], "create") == 0) { - strcat(buf, "You asked for us to create a model\n"); + + if (!argv[2] || !argv[3]) { + goto createEnd; + } + + if (strncmp(argv[2], "name=", 5) == 0) { + // TODO get the model name + + if (strncmp(argv[3], "file=", 5) == 0) { + // TODO get the file content (sent by the client) from args + + // Creating model + ModelCreate(&newModel); + + // TODO modify model according to things in file + + strcat(buf, "Model created with id"); + tempsize = sprintf(temp, " %d\n", newModel->id); + strcat(buf, temp); + goto CmdModelEnd; + + } else { + goto createEnd; + } + } else { + goto createEnd; + } + + createEnd: + // invalid use + strcat(buf, "Creates a model structure\n"); + strcat(buf, "Usage: model create name=NAME file=FILENAME\n"); + goto CmdModelEnd; } - if (strcmp(argv[1], "delete") == 0) { - strcat(buf, "You asked for us to delete a model\n"); + else if (strcmp(argv[1], "delete") == 0) { + if (!argv[2]) { + goto deleteEnd; + } + // TODO delete model + deleteEnd: + // invalid use + strcat(buf, "Deletes a model structure\n"); + strcat(buf, "Usage: model delete id=ID\n"); + goto CmdModelEnd; } - if (strcmp(argv[1], "load") == 0) { - strcat(buf, "You asked for us to load a model\n"); + else if (strcmp(argv[1], "run") == 0) { + if (!argv[2]) { + goto runEnd; + } + // TODO run model + runEnd: + // invalid use + strcat(buf, "Run a model simulation\n"); + strcat(buf, "Usage: model run id=ID\n"); + goto CmdModelEnd; } - if (strcmp(argv[1], "run") == 0) { - strcat(buf, "You asked for us to run a model\n"); + else if (strcmp(argv[1], "list") == 0) { + strcat(buf, "You asked for us to list models\n"); } + else if (strcmp(argv[1], "info") == 0) { + if (!argv[2]) { + goto infoEnd; + } + // TODO info model + infoEnd: + // invalid use + strcat(buf, "Print info about a model\n"); + strcat(buf, "Usage: model info id=ID\n"); + goto CmdModelEnd; + } + + // invalid use + else strcat(buf, "{create | delete | load | run | list | info}\n"); + CmdModelEnd: return buf; } @@ -74,7 +142,5 @@ char *CmdShutdown(char **argv, Server_t *args) args->pleaseStop = true; strcat(buf, "Server stopping\n"); - -CmdShutdownEnd: return buf; }