Subversion Repositories MLServ

Rev

Rev 3 | Rev 5 | Go to most recent revision | Blame | Compare with Previous | Last modification | View Log | Download | RSS feed

/* $Id: main.c 4 2024-09-24 18:35:15Z nishi $ */

#include <stdio.h>
#include <string.h>

#include "ms_newlist.h"
#include "ms_server.h"

#include <cm_version.h>

int main(int argc, char** argv) {
        int i;
        int startsub = 0;
        const char* option = NULL;
        for(i = 1; i < argc; i++) {
                if(argv[i][0] == '-') {
                        if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) {
                                printf("MLServ version %s\n", cm_get_version());
                                return 0;
                        } else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
                                printf("Usage: %s [options] [subcommand] [subcommand options/arguments]\n", argv[0]);
                                printf("Options:\n");
                                printf("-V | --version   Shows the version\n");
                                printf("-h | --help      Shows the help\n");
                                printf("Subcommands:\n");
                                printf("newlist          Creates a new list\n");
                                printf("server           Starts a server\n");
                                return 0;
                        } else {
                                fprintf(stderr, "Invalid flag: %s\n", argv[i]);
                                return 1;
                        }
                } else {
                        option = argv[i];
                        startsub = i + 1;
                        break;
                }
        }
        if(option == NULL) {
                fprintf(stderr, "Specify subcommand\n");
                return 1;
        } else if(strcmp(option, "newlist") == 0) {
                return ms_handle_newlist(argc, argv, startsub);
        } else if(strcmp(option, "server") == 0) {
                return ms_handle_server(argc, argv, startsub);
        } else {
                fprintf(stderr, "Invalid subcommand: %s\n", option);
                return 1;
        }
        return 0;
}