Before this change, I noticed that some non-interactive commands
don't work,
$ iwctl version
$ iwctl help
while other ones do.
$ iwctl station wlan0 show
This seems to be a typo bug in the if clause checking for additional
arguments.
There is a limitation of libreadline where no context/userdata
can be passed to completion functions. Thi affects iwctl since
the entity value isn't known to completion functions.
Workarounds such as getting the default device are employed but
its not a great solution.
Instead hack around this limitation by parsing the prompt to
extract the entity (second arg). Then use a generic match function
given to readline which can call the actual match function and
include the entity.
Previously, command_option_get used to return NULL in the following
two scenarios: when command-line option with a such name didn’t exists
or its argument was not provided. This worked great for the cmd-line
options with the required arguments. With introduction of the cmd-line
options with no or optional arguments the function was changed to return
a boolean value indicating the existence of a such option and then, if
it had an argument - value_out variable would have been set.
Thereafter, this patch modifies the current usages of command_option_get.
Note, in these particular applications of command_option_get there is no
need to check the returned value from command_option_get, since these
options have the required arguments and we can only check if the value_out
parameter has been set or not.
Instead of returning the mode of execution, command_init now
returns whether we are done and need to exit.
Thereafter, the mode of execution is now obtain though the command
module’s API.
Enable parsing of the command-line options by the command module.
The parsed command-line option values are stored in command_options
list and made available through the module’s public API:
command_option_get – allows querying options by name,
command_has_options – checks existence of the options.
Previously, on service disappeared event the list of the known
proxy objects was cleared, but pointers to the default entity
per command family wasn’t reset. Reset default entities for
the command families to remove the dead pointers to the deleted
proxy objects.
==1325== Invalid read of size 8
==1325== at 0x4055D4: proxy_interface_is_same (dbus-proxy.c:439)
==1325== by 0x407C28: match_by_partial_name (network.c:220)
==1325== by 0x40547C: proxy_interface_find_all (dbus-proxy.c:424)
==1325== by 0x405592: proxy_property_str_completion (dbus-proxy.c:153)
==1325== by 0x407DA9: network_name_completion (network.c:241)
==1325== by 0x4E596D5: rl_completion_matches (in /usr/lib64/libreadline.so.7.0)
The code would assume that a command with argc >= 3 would always be
composed of <family name> <entity> <command> and thus
"known-networks forget <ssid>" could not be executed. Instead of
checking argc >= 3 check whether command->entity is non-NULL.
This allows to inspect the cmd line for the existence of a provided
token. This enables the completers to look back to what was entered
before them and make decisions based on that information. For
example, this can be used in completion of the property values
to identify the property for which the value is being completed.