nmcli/connections: allow empty lists with "--ask c add"

The interactive add is not too enthusiastic about not providing a value
in a list.

That is before on getting an empty line in ask_option() we take a
shortcut instead of dispatching to set_option(). That way we skip
setting the PROPERTY_INF_FLAG_DISABLED flag, causing the option to
be included in questionnaire_one_optional()'s info list.

There's no reason to avoid calling set_option() if we don't get a value;
set_option() handles NULL value just fine.

  $ nmcli -a c add
  Connection type: dummy
  There is 1 optional setting for General settings.
  Do you want to provide it? (yes/no) [yes]
  Interface name [*]: lala
  There are 2 optional settings for IPv4 protocol.
  Do you want to provide them? (yes/no) [yes]
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  You can specify this option more than once. Press <Enter> when you're done.
  IPv4 address (IP[/plen]) [none]:
  ...
This commit is contained in:
Lubomir Rintel 2022-06-24 00:30:04 +02:00
parent d51140d2ab
commit a5e099d008

View file

@ -5591,8 +5591,6 @@ ask_option(NmCli *nmc, NMConnection *connection, const NMMetaAbstractInfo *abstr
again:
value = nmc_readline(&nmc->nmc_config, "%s", prompt);
if (multi && !value)
return;
if (!set_option(nmc, connection, abstract_info, value, FALSE, &error)) {
g_printerr("%s\n", error->message);