ci: Add help options; add checks for the boolean environment options

This commit is contained in:
Cosmin Truta 2024-01-22 23:45:23 +02:00
parent 4edbb4da81
commit 3285bf0d4c
6 changed files with 77 additions and 13 deletions

View File

@ -1,3 +1,7 @@
# Disable the "variable appears unused" warning caused by the use of getopts
# with an obligatory (but unused) variable name in the main function.
disable=SC2034
# Disable all the "quote to prevent globbing or word splitting" advice.
# We need word splitting for well-known variables like MAKEFLAGS and CFLAGS.
disable=SC2086,SC2206

View File

@ -1,7 +1,7 @@
#!/usr/bin/env bash
set -e
# Copyright (c) 2019-2023 Cosmin Truta.
# Copyright (c) 2019-2024 Cosmin Truta.
#
# Use, modification and distribution are subject
# to the Boost Software License, Version 1.0.
@ -58,11 +58,22 @@ function ci_lint_ci_scripts_license {
}
}
function usage {
echo "usage: $CI_SCRIPT_NAME"
exit 0
}
function main {
[[ $# -eq 0 ]] || {
ci_info "usage: $CI_SCRIPT_NAME"
ci_err "unexpected command argument: '$1'"
}
local opt
while getopts ":" opt
do
# This ain't a while-loop. It only pretends to be.
[[ $1 == -[?h]* || $1 == --help ]] && usage
ci_err "unknown option: '$1'"
done
shift $((OPTIND - 1))
# And... go!
[[ $# -eq 0 ]] || ci_err "unexpected argument: '$1'"
ci_lint_ci_config_files
ci_lint_ci_scripts
ci_lint_ci_scripts_license

View File

@ -169,12 +169,25 @@ function ci_build {
ci_info "## END OF BUILD ##"
}
function usage {
echo "usage: $CI_SCRIPT_NAME"
exit 0
}
function main {
local opt
while getopts ":" opt
do
# This ain't a while-loop. It only pretends to be.
[[ $1 == -[?h]* || $1 == --help ]] && usage
ci_err "unknown option: '$1'"
done
shift $((OPTIND - 1))
ci_init_build
ci_trace_build
[[ $# -eq 0 ]] || {
ci_info "note: this program accepts environment options only (see above)"
ci_err "unexpected command argument: '$1'"
ci_info "note: this program accepts environment options only"
ci_err "unexpected argument: '$1'"
}
ci_cleanup_old_build
ci_build

View File

@ -122,12 +122,26 @@ function ci_build {
ci_info "## END OF BUILD ##"
}
function usage {
echo "usage: $CI_SCRIPT_NAME"
exit 0
}
function main {
local opt
while getopts ":" opt
do
# This ain't a while-loop. It only pretends to be.
[[ $1 == -[?h]* || $1 == --help ]] && usage
ci_err "unknown option: '$1'"
done
shift $((OPTIND - 1))
# And... go!
ci_init_build
ci_trace_build
[[ $# -eq 0 ]] || {
ci_info "note: this program accepts environment options only (see above)"
ci_err "unexpected command argument: '$1'"
ci_info "note: this program accepts environment options only"
ci_err "unexpected argument: '$1'"
}
ci_cleanup_old_build
ci_build

View File

@ -137,12 +137,26 @@ function ci_build {
ci_info "## END OF BUILD ##"
}
function usage {
echo "usage: $CI_SCRIPT_NAME"
exit 0
}
function main {
local opt
while getopts ":" opt
do
# This ain't a while-loop. It only pretends to be.
[[ $1 == -[?h]* || $1 == --help ]] && usage
ci_err "unknown option: '$1'"
done
shift $((OPTIND - 1))
# And... go!
ci_init_build
ci_trace_build
[[ $# -eq 0 ]] || {
ci_info "note: this program accepts environment options only (see above)"
ci_err "unexpected command argument: '$1'"
ci_info "note: this program accepts environment options only"
ci_err "unexpected argument: '$1'"
}
ci_cleanup_old_build
ci_build

View File

@ -1,4 +1,4 @@
# Copyright (c) 2019-2023 Cosmin Truta.
# Copyright (c) 2019-2024 Cosmin Truta.
#
# Use, modification and distribution are subject
# to the Boost Software License, Version 1.0.
@ -73,7 +73,7 @@ function ci_spawn {
"$@"
}
# Ensure that the initialization is correct.
# Ensure that the internal initialization is correct.
[[ $CI_TOPLEVEL_DIR/ci/lib/ci.lib.sh -ef ${BASH_SOURCE[0]} ]] ||
ci_err_internal "bad or missing \$CI_TOPLEVEL_DIR"
[[ $CI_SCRIPT_DIR/$CI_SCRIPT_NAME -ef $0 ]] ||
@ -82,3 +82,11 @@ function ci_spawn {
ci_err_internal "missing \$CI_BUILD_ARCH or \$CI_BUILD_SYSTEM"
[[ $CI_TARGET_ARCH && $CI_TARGET_SYSTEM ]] ||
ci_err_internal "missing \$CI_TARGET_ARCH or \$CI_TARGET_SYSTEM"
# Ensure that the user initialization is correct.
[[ ${CI_NO_TEST:-0} == [01] ]] ||
ci_err "bad boolean option: \$CI_NO_TEST: '$CI_NO_TEST'"
[[ ${CI_NO_INSTALL:-0} == [01] ]] ||
ci_err "bad boolean option: \$CI_NO_INSTALL: '$CI_NO_INSTALL'"
[[ ${CI_NO_CLEAN:-0} == [01] ]] ||
ci_err "bad boolean option: \$CI_NO_CLEAN: '$CI_NO_CLEAN'"