Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Maintain default option when internally calling bash function #250

Closed
sarnrich opened this issue Sep 27, 2023 · 1 comment
Closed

Maintain default option when internally calling bash function #250

sarnrich opened this issue Sep 27, 2023 · 1 comment

Comments

@sarnrich
Copy link

#!/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?

@sigoden
Copy link
Owner

sigoden commented Sep 27, 2023

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
}

@sigoden sigoden closed this as completed Sep 27, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants