Skip to content

Commit

Permalink
Merge pull request #204 from tegonal/improve/parse-args-print-help
Browse files Browse the repository at this point in the history
parse-args print help only on demand to clutter less the output
  • Loading branch information
robstoll authored Oct 18, 2024
2 parents 87b55c2 + b882ccc commit 8e7f2c8
Showing 1 changed file with 4 additions and 2 deletions.
6 changes: 4 additions & 2 deletions src/utility/parse-args.sh
Original file line number Diff line number Diff line change
Expand Up @@ -74,6 +74,7 @@ if ! [[ -v dir_of_tegonal_scripts ]]; then
source "$dir_of_tegonal_scripts/setup.sh" "$dir_of_tegonal_scripts"
fi
sourceOnce "$dir_of_tegonal_scripts/utility/array-utils.sh"
sourceOnce "$dir_of_tegonal_scripts/utility/ask.sh"
sourceOnce "$dir_of_tegonal_scripts/utility/checks.sh"
sourceOnce "$dir_of_tegonal_scripts/utility/parse-utils.sh"

Expand Down Expand Up @@ -186,13 +187,14 @@ function parseArgumentsInternal {
done

if [[ $parseArguments_unknownBehaviour = 'error' ]] && ((parseArguments_expectedName == 0)); then
parse_args_printHelp >&2 parseArguments_paramArr "$parseArguments_examples" "$parseArguments_version"
if [[ $parseArguments_argName =~ ^- ]] && (($# > 1)); then
logError "unknown argument \033[1;36m%s\033[0m (and value %s)" "$parseArguments_argName" "$2"
else
logError "unknown argument \033[1;36m%s\033[0m" "$parseArguments_argName"
fi
echo >&2 "consult the output of --help shown further above for valid names"
if askYesOrNo "Shall I print the help for you?"; then
parse_args_printHelp >&2 parseArguments_paramArr "$parseArguments_examples" "$parseArguments_version"
fi
exit 9
fi
shift 1 || traceAndDie "could not shift by 1"
Expand Down

0 comments on commit 8e7f2c8

Please sign in to comment.