#include "uci.h"
static const char *appname = "uci";
+static enum {
+ CLI_FLAG_MERGE = (1 << 0),
+} flags;
+static FILE *input = stdin;
static struct uci_context *ctx;
enum {
CMD_RENAME,
/* package cmds */
CMD_SHOW,
+ CMD_IMPORT,
CMD_EXPORT,
CMD_COMMIT,
};
fprintf(stderr,
"Usage: %s [<options>] <command> [<arguments>]\n\n"
"Commands:\n"
- "\texport [<config>]\n"
- "\tshow [<config>[.<section>[.<option>]]]\n"
- "\tget <config>.<section>[.<option>]\n"
- "\tset <config>.<section>[.<option>]=<value>\n"
+ "\texport [<config>]\n"
+ "\timport [<config>]\n"
+ "\tshow [<config>[.<section>[.<option>]]]\n"
+ "\tget <config>.<section>[.<option>]\n"
+ "\tset <config>.<section>[.<option>]=<value>\n"
+ "\trename <config>.<section>[.<option>]=<name>\n"
"\n"
"Options:\n"
- "\t-s force strict mode (stop on parser errors)\n"
- "\t-S disable strict mode\n"
+ "\t-f <file> use <file> as input instead of stdin\n"
+ "\t-m when importing, merge data into an existing package\n"
+ "\t-s force strict mode (stop on parser errors)\n"
+ "\t-S disable strict mode\n"
"\n",
argv[0]
);
return 0;
}
+static int uci_do_import(int argc, char **argv)
+{
+ return 0;
+}
+
static int uci_do_package_cmd(int cmd, int argc, char **argv)
{
char **configs = NULL;
static int uci_do_section_cmd(int cmd, int argc, char **argv)
{
+ struct uci_package *p = NULL;
+ struct uci_element *e = NULL;
char *package = NULL;
char *section = NULL;
char *option = NULL;
char *value = NULL;
char **ptr = NULL;
- struct uci_package *p = NULL;
- struct uci_element *e = NULL;
+ int ret = UCI_OK;
if (argc != 2)
return 255;
printf("%s\n", value);
break;
case CMD_RENAME:
- if (uci_rename(ctx, p, section, option, value) != UCI_OK) {
- uci_perror(ctx, appname);
- return 1;
- }
+ ret = uci_rename(ctx, p, section, option, value);
break;
case CMD_SET:
- if (uci_set(ctx, p, section, option, value) != UCI_OK) {
- uci_perror(ctx, appname);
- return 1;
- }
+ ret = uci_set(ctx, p, section, option, value);
break;
case CMD_DEL:
- if (uci_delete(ctx, p, section, option) != UCI_OK) {
- uci_perror(ctx, appname);
- return 1;
- }
+ ret = uci_delete(ctx, p, section, option);
break;
}
return 0;
/* save changes, but don't commit them yet */
- if (uci_save(ctx, p) != UCI_OK) {
+ if (ret == UCI_OK)
+ ret = uci_save(ctx, p);
+
+ if (ret != UCI_OK) {
uci_perror(ctx, appname);
return 1;
}
cmd = CMD_RENAME;
else if (!strcasecmp(argv[0], "del"))
cmd = CMD_DEL;
+ else if (!strcasecmp(argv[0], "import"))
+ cmd = CMD_IMPORT;
else
cmd = -1;
case CMD_EXPORT:
case CMD_COMMIT:
return uci_do_package_cmd(cmd, argc, argv);
+ case CMD_IMPORT:
+ return uci_do_import(argc, argv);
default:
return 255;
}
while((c = getopt(argc, argv, "sS")) != -1) {
switch(c) {
+ case 'f':
+ input = fopen(optarg, "r");
+ if (!input) {
+ perror("uci");
+ return 1;
+ }
+ break;
+ case 'm':
+ flags |= CLI_FLAG_MERGE;
+ break;
case 's':
ctx->flags |= UCI_FLAG_STRICT;
break;
if (argc < 2)
uci_usage(argc, argv);
ret = uci_cmd(argc - 1, argv + 1);
+ if (input != stdin)
+ fclose(input);
if (ret == 255)
uci_usage(argc, argv);