summaryrefslogtreecommitdiff
path: root/src/third_party/wiredtiger/src/utilities/util_create.c
blob: 574f7c1ec1ddce7966beec80dc7aef5ed45039e1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
/*-
 * Copyright (c) 2014-present MongoDB, Inc.
 * Copyright (c) 2008-2014 WiredTiger, Inc.
 *	All rights reserved.
 *
 * See the file LICENSE for redistribution information.
 */

#include "util.h"

/*
 * usage --
 *     TODO: Add a comment describing this function.
 */
static int
usage(void)
{
    static const char *options[] = {
      "-c config", "a configuration string to be passed to WT_SESSION.create", NULL, NULL};

    util_usage("create [-c configuration] uri", "options:", options);
    return (1);
}

/*
 * util_create --
 *     TODO: Add a comment describing this function.
 */
int
util_create(WT_SESSION *session, int argc, char *argv[])
{
    WT_DECL_RET;
    int ch;
    char *config, *uri;

    config = uri = NULL;
    while ((ch = __wt_getopt(progname, argc, argv, "c:")) != EOF)
        switch (ch) {
        case 'c': /* command-line configuration */
            config = __wt_optarg;
            break;
        case '?':
        default:
            return (usage());
        }

    argc -= __wt_optind;
    argv += __wt_optind;

    /* The remaining argument is the uri. */
    if (argc != 1)
        return (usage());

    if ((uri = util_uri(session, *argv, "table")) == NULL)
        return (1);

    if ((ret = session->create(session, uri, config)) != 0)
        (void)util_err(session, ret, "session.create: %s", uri);

    free(uri);
    return (ret);
}