- for (p = configs; *p; p++) {
- if ((argc < 2) || !strcmp(argv[1], *p)) {
- struct uci_package *package = NULL;
- int ret;
-
- ret = uci_load(ctx, *p, &package);
- if (ret)
- continue;
- uci_export(ctx, stdout, package, true);
- uci_unload(ctx, package);
+ if (argc == 2)
+ name = argv[1];
+ else if (flags & CLI_FLAG_MERGE)
+ /* need a package to merge */
+ return 255;
+
+ if (flags & CLI_FLAG_MERGE) {
+ if (uci_load(ctx, name, &package) != UCI_OK)
+ package = NULL;
+ else
+ merge = true;
+ }
+ ret = uci_import(ctx, input, name, &package, (name != NULL));
+ if (ret == UCI_OK) {
+ if (merge) {
+ ret = uci_save(ctx, package);
+ } else {
+ struct uci_element *e;
+ /* loop through all config sections and overwrite existing data */
+ uci_foreach_element(&ctx->root, e) {
+ struct uci_package *p = uci_to_package(e);
+ ret = uci_commit(ctx, &p, true);
+ }