d83e257e4e2d3ec1e4d362acf60e81c4de15546d
[project/uci.git] / cli.c
1 /*
2  * Copyright (C) 2008 Felix Fietkau <nbd@openwrt.org>
3  *
4  * This program is free software; you can redistribute it and/or modify
5  * it under the terms of the GNU General Public License version 2
6  * as published by the Free Software Foundation
7  *
8  * This program is distributed in the hope that it will be useful,
9  * but WITHOUT ANY WARRANTY; without even the implied warranty of
10  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
11  * GNU General Public License for more details.
12  */
13 #include <strings.h>
14 #include <stdlib.h>
15 #include "uci.h"
16
17 static struct uci_context *ctx;
18
19 static void uci_usage(int argc, char **argv)
20 {
21         fprintf(stderr,
22                 "Usage: %s [options] <command> [arguments]\n\n"
23                 "Commands:\n"
24                 "\tshow [<config>[.<section>[.<option>]]]\n"
25                 "\n",
26                 argv[0]
27         );
28         exit(255);
29 }
30
31 static int uci_show(int argc, char **argv)
32 {
33         char **configs = uci_list_configs(ctx);
34         char **p;
35
36         if (!configs)
37                 return 0;
38
39         for (p = configs; *p; p++) {
40                 fprintf(stderr, "# config: %s\n", *p);
41         }
42
43         return 0;
44 }
45
46 static int uci_cmd(int argc, char **argv)
47 {
48         if (!strcasecmp(argv[0], "show"))
49                 uci_show(argc, argv);
50         return 0;
51 }
52
53 int main(int argc, char **argv)
54 {
55         int ret;
56
57         ctx = uci_alloc();
58         if (argc < 2)
59                 uci_usage(argc, argv);
60         ret = uci_cmd(argc - 1, argv + 1);
61         uci_free(ctx);
62
63         return ret;
64 }