sigoden/argc

Maintain default option when internally calling bash function

sarnrich opened this issue · 1 comments

#!/bin/bash

# @cmd A wrapper for multiple subcommands
wrapper() {
  subcommandA
  # subcommandB
  # subcommandC
}

# @cmd A subcommand
# @option --sub_option=defaultValue
subcommandA() {
  echo "subcommandA ${argc_sub_option}"
}
eval "$(argc --argc-eval "$0" "$@")"
$ ./test subcommandA
subcommandA defaultValue

$ ./test wrapper
subcommandA

If a subcommand "wrapper" consists of multiple other subcommands, the subcommands option default values are not beeing present.
Is this expected behavior?

This is expected behavior.

Calling a subcommand function is no different from calling an ordinary function.

If you want to run a subcommand, use the argc or bash:

# @cmd A wrapper for multiple subcommands
wrapper() {
    argc subcommandA   # Only If wrapper can be called with `argc wrapper`
}

# @cmd A wrapper for multiple subcommands
wrapper() {
    bash "$BASH_SOURCE" subcommandA
}