cli model command (create)
This commit is contained in:
parent
cca06c9ec6
commit
e6ac4a3e91
86
src/cmds.c
86
src/cmds.c
|
@ -36,28 +36,96 @@ 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 (strcmp(argv[1], "delete") == 0) {
|
||||
strcat(buf, "You asked for us to delete a model\n");
|
||||
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;
|
||||
}
|
||||
|
||||
if (strcmp(argv[1], "load") == 0) {
|
||||
strcat(buf, "You asked for us to load a model\n");
|
||||
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], "run") == 0) {
|
||||
strcat(buf, "You asked for us to run 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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue