config: catch and report unexpected arguments

after handling arguments, catch and report any remaining "non-option"
arguments.

for instance users could make the basic mistake of using
`lb config --bootloaders syslinux grub-efi`, i.e. failing to quote the
multiple bootloaders (i actually encountered a user doing this who swore
that "it just worked"). catching and reporting such mistakes could be
valuable to users.

previous behaviour:
```
$ lb config --bootloaders syslinux grub-efi
P: Updating config tree for a debian/buster/amd64 system
P: Symlinking hooks...
```

new behaviour:
```
$ lb config --bootloaders syslinux grub-efi
[2020-05-05 18:56:07] lb config --bootloaders syslinux grub-efi
E: Unexpected argument found: grub-efi
```

Gbp-Dch: Short
This commit is contained in:
Lyndon Brown 2020-05-05 18:58:39 +01:00
parent d68290058e
commit 665372c19d
1 changed files with 9 additions and 0 deletions

View File

@ -822,6 +822,15 @@ Local_arguments ()
;;
esac
done
# Any remaining arguments should be reported as an unexpected arguments error.
if [ $# -ne 0 ]; then
local ARG
for ARG in "${@}"; do
Echo_error "Unexpected argument found: %s" "${ARG}"
done
exit 1
fi
}
# Processing args such that we have a value for --config if given