From 85a95118d4427f9d49a227f91f379be5bec385e3 Mon Sep 17 00:00:00 2001 From: merakor Date: Tue, 3 Nov 2020 15:08:19 +0000 Subject: cpt-lib: fix shellcheck error FossilOrigin-Name: 9b88780f4576b44b7578dd7758f8c2a967d11ff6a86566c08dd5b4ccf04f2309 --- src/cpt-lib | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/cpt-lib b/src/cpt-lib index f69aca1..a9522e8 100644 --- a/src/cpt-lib +++ b/src/cpt-lib @@ -230,6 +230,8 @@ getoptions() { _1 'exit 1' _0 '}' + # This throws an error on older versions of shellcheck. + # shellcheck disable=2086 [ ! "$_help" ] || eval "shift 2; getoptions_help $1 $_help" ${3+'"$@"'} } # URL: https://github.com/ko1nksm/getoptions (v2.0.1) -- cgit v1.2.3 From 13e58869dc0bf24acacc98650ef95d0d27598a4f Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 9 Nov 2020 13:03:20 +0000 Subject: getoptions(): parse the options during main() call on cpt-lib Calling parse() after cpt-lib has been called causes sys_db to be initiated using the wrong CPT_ROOT, among other issues. By calling the option parser during the main(), we make sure that the options parsed are used as soon as possible. FossilOrigin-Name: 2933b99bec8ec9c3f20143e2a19c270a6d208f723d2b394c625cbc13d2625326 --- src/cpt-build | 7 +------ src/cpt-install | 7 +------ src/cpt-lib | 8 ++++++++ src/cpt-list | 7 +------ src/cpt-remove | 8 +------- src/cpt-search | 7 +------ src/cpt-update | 8 +------- 7 files changed, 14 insertions(+), 38 deletions(-) diff --git a/src/cpt-build b/src/cpt-build index 389c824..d67f1a6 100755 --- a/src/cpt-build +++ b/src/cpt-build @@ -1,8 +1,6 @@ #!/bin/sh # Build a package -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [pkg...]" msg -- '' 'Options:' @@ -10,10 +8,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi [ "$1" ] || set -- "${PWD##*/}"; export CPT_PATH=${PWD%/*}:$CPT_PATH diff --git a/src/cpt-install b/src/cpt-install index 4dadcda..b046e02 100755 --- a/src/cpt-install +++ b/src/cpt-install @@ -1,8 +1,6 @@ #!/bin/sh # Install a package -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [pkg...]" msg -- '' 'Options:' @@ -10,10 +8,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi [ "$1" ] || set -- "${PWD##*/}"; export CPT_PATH=${PWD%/*}:$CPT_PATH diff --git a/src/cpt-lib b/src/cpt-lib index a9522e8..e5d526a 100644 --- a/src/cpt-lib +++ b/src/cpt-lib @@ -1777,6 +1777,14 @@ create_cache() { main() { set -ef + # If a parser definition exists, let's run it ourselves. This makes sure we + # get the variables as soon as possible. + command -v parser_definition >/dev/null && { + eval "$(getoptions parser_definition parse "$0")" + parse "$@" + eval set -- "$REST" + } + # Create the cache directories for CPT and set the variables which point # to them. This is seperate from temporary directories created in # create_cache(). That's because we need these variables set on most diff --git a/src/cpt-list b/src/cpt-list index aaef8d9..a161abf 100755 --- a/src/cpt-list +++ b/src/cpt-list @@ -1,8 +1,6 @@ #!/bin/sh -ef # List installed packages -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [-c] [pkg...]" msg -- '' 'Options:' @@ -10,10 +8,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi [ "$CURRENT" ] && set -- "${PWD##*/}" diff --git a/src/cpt-remove b/src/cpt-remove index b6fed58..bcf5047 100755 --- a/src/cpt-remove +++ b/src/cpt-remove @@ -1,8 +1,6 @@ #!/bin/sh -ef # Remove a package -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [pkg...]" msg -- '' 'Options:' @@ -10,10 +8,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi [ "$1" ] || set -- "${PWD##*/}"; export CPT_PATH=${PWD%/*}:$CPT_PATH @@ -23,6 +18,5 @@ eval set -- "$REST" } create_cache - pkg_order "$@" for pkg in $redro; do pkg_remove "$pkg" "${CPT_FORCE:-check}"; done diff --git a/src/cpt-search b/src/cpt-search index f943aca..df27761 100755 --- a/src/cpt-search +++ b/src/cpt-search @@ -1,8 +1,6 @@ #!/bin/sh -ef # Search for a package -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [pkg...]" msg -- '' 'Options:' @@ -12,10 +10,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi # The 'all' variable is set by the option parser. # shellcheck disable=2154 diff --git a/src/cpt-update b/src/cpt-update index b3884e3..a8f9616 100755 --- a/src/cpt-update +++ b/src/cpt-update @@ -1,8 +1,6 @@ #!/bin/sh -ef # Check for updates -if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi - parser_definition() { setup REST help:usage -- "usage: ${0##*/} [options]" msg -- '' 'Options:' @@ -12,11 +10,7 @@ parser_definition() { global_options } -eval "$(getoptions parser_definition parse "$0")" - -parse "$@" -eval set -- "$REST" +if [ -f ./cpt-lib ]; then . ./cpt-lib; else . cpt-lib; fi create_cache - pkg_updates -- cgit v1.2.3 From c10e49d9caf08d0729024f5cf770634a739ebbe3 Mon Sep 17 00:00:00 2001 From: merakor Date: Mon, 9 Nov 2020 13:21:18 +0000 Subject: cpt-lib: don't make main() a function unto itself FossilOrigin-Name: 3f01d4659d9f4e7488387436153fc9a20723b40f28515c5020172a83eb88128b --- src/cpt-lib | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/cpt-lib b/src/cpt-lib index e5d526a..9cd3d2d 100644 --- a/src/cpt-lib +++ b/src/cpt-lib @@ -1774,7 +1774,8 @@ create_cache() { } -main() { +# main() +{ set -ef # If a parser definition exists, let's run it ourselves. This makes sure we @@ -1875,5 +1876,3 @@ main() { fi } - -main "$@" -- cgit v1.2.3