From 6b7c8ed4bf15175299729355f04d60dcbac1aded Mon Sep 17 00:00:00 2001 From: Lyndon Brown Date: Wed, 18 Mar 2020 01:51:53 +0000 Subject: frontend: properly handle option processing this means that the usage goes from: lb {-h|--help|-u|--usage|-v|--version} lb COMMAND [OPTIONS] to: lb {-h|--help|-u|--usage|-v|--version} lb [FRONTEND_OPTIONS] COMMAND [COMMAND_OPTIONS] though it is probably not worth is to update the description in the manpages...? hmm... so for instance this matters for color control with --color|--no-color (you already had full control via environment vars). previously you could do `lb COMMAND --no-color` to turn off colour, only to find that output at the frontend level was still coloured (the option is processed at the command context level, not the frontend), so you might try to instead use `lb --no-color COMMAND`, only to find that this was not supported. Well now it is, and used at the frontend level will fully control colour output (after the command is processed anyway). the full set of common options are thus available (except --force) at the frontend level, and thus for instance all Echo_*() helpers used in the frontend will work correctly after args are processed. furthermore usage like `lb --color --help` will actually work. (not that color is used there, but this previously would have failed with the frontend treating the `--color` argument as the command; that's the point!) Gbp-Dch: Short --- frontend/lb | 25 +++++++------------------ 1 file changed, 7 insertions(+), 18 deletions(-) (limited to 'frontend/lb') diff --git a/frontend/lb b/frontend/lb index 137867be2..1d8b89ab6 100755 --- a/frontend/lb +++ b/frontend/lb @@ -19,25 +19,14 @@ DESCRIPTION="Utility to build live systems" HELP="" USAGE="lb {clean|config|build}" -case "${1}" in - -h|--help) - if [ $(which man) ]; then - man lb - else - Usage - fi - exit 0 - ;; +# Handle options up to any command +# We replace the arg set with any remaining args on return +Arguments frontend "${@}" +eval set -- "${REMAINING_ARGS}" - ""|-u|--usage) - Usage - ;; - - -v|--version) - echo "${VERSION}" - exit 0 - ;; -esac +if [ -z "${1}" ]; then + Usage +fi COMMAND="${1}" shift -- cgit v1.2.3