@@ -1206,37 +1206,31 @@ static void
nbctl_lr_add(struct ctl_context *ctx)
{
const char *lr_name = ctx->argc == 2 ? ctx->argv[1] : NULL;
+ if (lr_name == NULL)
+ ctl_fatal("lr-add requires specifying a name");
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
bool add_duplicate = shash_find(&ctx->options, "--add-duplicate") != NULL;
if (may_exist && add_duplicate) {
ctl_fatal("--may-exist and --add-duplicate may not be used together");
}
-
- if (lr_name) {
- if (!add_duplicate) {
- const struct nbrec_logical_router *lr;
- NBREC_LOGICAL_ROUTER_FOR_EACH (lr, ctx->idl) {
- if (!strcmp(lr->name, lr_name)) {
- if (may_exist) {
- return;
- }
- ctl_fatal("%s: a router with this name already exists",
- lr_name);
- }
+
+ if (!add_duplicate) {
+ const struct nbrec_logical_router *lr;
+ NBREC_LOGICAL_ROUTER_FOR_EACH (lr, ctx->idl) {
+ if (!strcmp(lr->name, lr_name)) {
+ if (may_exist)
+ return;
+
+ ctl_fatal("%s: a router with this name already exists",
+ lr_name);
}
}
- } else if (may_exist) {
- ctl_fatal("--may-exist requires specifying a name");
- } else if (add_duplicate) {
- ctl_fatal("--add-duplicate requires specifying a name");
}
struct nbrec_logical_router *lr;
lr = nbrec_logical_router_insert(ctx->txn);
- if (lr_name) {
- nbrec_logical_router_set_name(lr, lr_name);
- }
+ nbrec_logical_router_set_name(lr, lr_name);
}
@@ -526,6 +526,8 @@ static void
nbctl_ls_add(struct ctl_context *ctx)
{
const char *ls_name = ctx->argc == 2 ? ctx->argv[1] : NULL;
+ if (ls_name == NULL)
+ ctl_fatal("ls-add requires specifying a name");
bool may_exist = shash_find(&ctx->options, "--may-exist") != NULL;
bool add_duplicate = shash_find(&ctx->options, "--add-duplicate") != NULL;
@@ -533,30 +535,22 @@ nbctl_ls_add(struct ctl_context *ctx)
ctl_fatal("--may-exist and --add-duplicate may not be used together");
}
- if (ls_name) {
- if (!add_duplicate) {
- const struct nbrec_logical_switch *ls;
- NBREC_LOGICAL_SWITCH_FOR_EACH (ls, ctx->idl) {
- if (!strcmp(ls->name, ls_name)) {
- if (may_exist) {
- return;
- }
- ctl_fatal("%s: a switch with this name already exists",
- ls_name);
- }
+ if (!add_duplicate) {
+ const struct nbrec_logical_switch *ls;
+ NBREC_LOGICAL_SWITCH_FOR_EACH (ls, ctx->idl) {
+ if (!strcmp(ls->name, ls_name)) {
+ if (may_exist)
+ return;
+
+ ctl_fatal("%s: a switch with this name already exists",
+ ls_name);
}
}
- } else if (may_exist) {
- ctl_fatal("--may-exist requires specifying a name");
- } else if (add_duplicate) {
- ctl_fatal("--add-duplicate requires specifying a name");
}
struct nbrec_logical_switch *ls;
ls = nbrec_logical_switch_insert(ctx->txn);
- if (ls_name) {
- nbrec_logical_switch_set_name(ls, ls_name);
- }
+ nbrec_logical_switch_set_name(ls, ls_name);
}