Subversion Repositories MLServ

Rev

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

Rev Author Line No. Line
1 nishi 1
/* $Id: main.c 4 2024-09-24 18:35:15Z nishi $ */
2
 
4 nishi 3
#include <stdio.h>
4
#include <string.h>
5
 
6
#include "ms_newlist.h"
7
#include "ms_server.h"
8
 
9
#include <cm_version.h>
10
 
11
int main(int argc, char** argv) {
12
	int i;
13
	int startsub = 0;
14
	const char* option = NULL;
15
	for(i = 1; i < argc; i++) {
16
		if(argv[i][0] == '-') {
17
			if(strcmp(argv[i], "--version") == 0 || strcmp(argv[i], "-V") == 0) {
18
				printf("MLServ version %s\n", cm_get_version());
19
				return 0;
20
			} else if(strcmp(argv[i], "--help") == 0 || strcmp(argv[i], "-h") == 0) {
21
				printf("Usage: %s [options] [subcommand] [subcommand options/arguments]\n", argv[0]);
22
				printf("Options:\n");
23
				printf("-V | --version   Shows the version\n");
24
				printf("-h | --help      Shows the help\n");
25
				printf("Subcommands:\n");
26
				printf("newlist          Creates a new list\n");
27
				printf("server           Starts a server\n");
28
				return 0;
29
			} else {
30
				fprintf(stderr, "Invalid flag: %s\n", argv[i]);
31
				return 1;
32
			}
33
		} else {
34
			option = argv[i];
35
			startsub = i + 1;
36
			break;
37
		}
38
	}
39
	if(option == NULL) {
40
		fprintf(stderr, "Specify subcommand\n");
41
		return 1;
42
	} else if(strcmp(option, "newlist") == 0) {
43
		return ms_handle_newlist(argc, argv, startsub);
44
	} else if(strcmp(option, "server") == 0) {
45
		return ms_handle_server(argc, argv, startsub);
46
	} else {
47
		fprintf(stderr, "Invalid subcommand: %s\n", option);
48
		return 1;
49
	}
50
	return 0;
51
}