Skip to content

Do not shift after parsing args if the only defined arg is help #204

@yeldiRium

Description

@yeldiRium

After using argbash for quite a few arguments-heavy scripts and liking it a lot, I started to add it to most of my scripts to have a consistent help text and to be able to declare used environment variables.
During that I encountered the very minor issue, that argbash produces code that contains a shellcheck error when no arguments are defined.

A minimal example looks like this:

#!/usr/bin/env bash

# ARG_HELP([Does a thing])
# ARG_USE_ENV([SOME_ENV],[],[Contains important config])
# ARGBASH_GO()
# [ <-- needed because of Argbash

echo "${SOME_ENV}"

# ] <-- needed because of Argbash

This produces the following argument parsing code:

parse_commandline()
{
	while test $# -gt 0
	do
		_key="$1"
		case "$_key" in
			-h|--help)
				print_help
				exit 0
				;;
			-h*)
				print_help
				exit 0
				;;
			*)
				_PRINT_HELP=yes die "FATAL ERROR: Got an unexpected argument '$1'" 1
				;;
		esac
		shift
	done
}

Shellcheck complains about the shift in line 19, since it is unreachable.
I would expect argbash to realize this and omit the shift.

As I said I think this is a very minor issue.
If I get around to reading more m4, I might open another PR.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions