main.cpp 2.0 KB
Newer Older
G
groot 已提交
1 2 3 4 5 6 7 8 9 10 11
////////////////////////////////////////////////////////////////////////////////
// Copyright 上海赜睿信息科技有限公司(Zilliz) - All Rights Reserved
// Unauthorized copying of this file, via any medium is strictly prohibited.
// Proprietary and confidential.
////////////////////////////////////////////////////////////////////////////////

#include <getopt.h>
#include <libgen.h>
#include <cstring>
#include <string>

G
refine  
groot 已提交
12
#include "src/ClientTest.h"
G
groot 已提交
13 14 15

void print_help(const std::string &app_name);

G
groot 已提交
16

G
groot 已提交
17 18 19 20 21
int
main(int argc, char *argv[]) {
    printf("Client start...\n");

    std::string app_name = basename(argv[0]);
G
groot 已提交
22 23
    static struct option long_options[] = {{"server", optional_argument, 0, 's'},
                                           {"port", optional_argument, 0, 'p'},
G
groot 已提交
24 25 26 27
                                           {"help", no_argument, 0, 'h'},
                                           {NULL, 0, 0, 0}};

    int option_index = 0;
G
groot 已提交
28
    std::string address = "127.0.0.1", port = "19530";
G
groot 已提交
29 30 31
    app_name = argv[0];

    int value;
G
groot 已提交
32
    while ((value = getopt_long(argc, argv, "s:p:h", long_options, &option_index)) != -1) {
G
groot 已提交
33
        switch (value) {
G
groot 已提交
34
            case 's': {
G
groot 已提交
35 36 37 38 39 40 41
                char *address_ptr = strdup(optarg);
                address = address_ptr;
                free(address_ptr);
                break;
            }
            case 'p': {
                char *port_ptr = strdup(optarg);
G
groot 已提交
42
                port = port_ptr;
G
groot 已提交
43
                free(port_ptr);
G
groot 已提交
44 45
                break;
            }
G
groot 已提交
46
            case 'h':
G
groot 已提交
47
            default:
G
groot 已提交
48 49
                print_help(app_name);
                return EXIT_SUCCESS;
G
groot 已提交
50 51 52
        }
    }

G
groot 已提交
53 54
    ClientTest test;
    test.Test(address, port);
G
groot 已提交
55

G
groot 已提交
56
    printf("Client stop...\n");
G
refine  
groot 已提交
57
    return 0;
G
groot 已提交
58 59 60 61 62 63
}

void
print_help(const std::string &app_name) {
    printf("\n Usage: %s [OPTIONS]\n\n", app_name.c_str());
    printf("  Options:\n");
G
groot 已提交
64
    printf("   -s --server   Server address, default 127.0.0.1\n");
G
groot 已提交
65
    printf("   -p --port     Server port, default 19530\n");
G
groot 已提交
66
    printf("   -h --help     Print help information\n");
G
groot 已提交
67 68
    printf("\n");
}