sigoden/argc

Argc is checking for non-cmd/alias function duplicates

lionelnicolas opened this issue · 0 comments

argc is checking all functions for duplicates, but it should only check top-level ones which are tagged with @cmd or @alias.

Reproducer:

#!/bin/sh

# unused function
util_func() {
	case $(basename ${SHELL}) in
		zsh)
			_local_func() {
				echo "do this"
			}
			;;

		bash)
			_local_func() {
				echo "do that instead"
			}
			;;
	esac
}

# @cmd Run tests
test() {
	echo "do something"
}

eval "$(argc "$0" "$@")"

If I run the script, argc exits with the following error:

_local_func(line 13) is conflicted with cmd or alias at line 7

IMHO, _local_func() should not be checked for duplicates, as well as util_func() because none of them have @cmd or @alias tags,

Also, all forms of heredoc should be ignored too. For example, using the following script:

#!/bin/sh

# just a random heredoc
cat >/dev/null <<EOF
func_test() {
	echo test
}
func_test() {
	echo test
}
EOF

# @cmd Run tests
test() {
	echo "do something"
}

eval "$(argc "$0" "$@")"

argc exits with the following error:

func_test(line 8) is conflicted with cmd or alias at line 5

This seems to be a regression as the two above example are working with v0.12.0, but failing with v0.13.0.