Skip to content

Access default value #562

@zeroSteiner

Description

@zeroSteiner

Description

First, thanks so much for your work on bashly, it's a fantastic project.

I'm hoping to request a feature to access the default value from the YAML definition to prevent the need for repeating it in the bash code. For my use case, I have this option definition:

  - long: --option
    arg: option
    help: Options to add to the certificate
    repeatable: true
    validate: is_valid_signing_option
    default:
      - permit-agent-forwarding
      - permit-port-forwarding
      - permit-pty

When the user specifies the --option flag, the defaults are all removed. My use case is probably uncommon, but I'd like to maintain the array to allow the user to pass multiple keys prefixed with permit or no and they'll be merged into the result as a set of enabled options. I have all of that working, but as it is now I have to have my defaults defined both in the YAML so they can be shown to the user and in the bash code, so that if only one flag is disabled the others will still be set. Basically, I'd like to be able to merge them myself by detecting the value of args[--option] isn't the default like this (assuming the function named arg_option_default returns the default value):

options="${args[--option]}"

# Get the default value from arg_option_default
default_value=$(arg_option_default)

# Check if the string equals the default value
if [[ "$options" != "$default_value" ]]; then
    # Prepend the default value to the string if they are not equal
    options="${default_value} ${options}"
fi

I was thinking there would probably be other use cases for checking if a value is non-default as well but I guess an alternative solution could be a flag to allow repeatable options to be appended to the specified default.

Metadata

Metadata

Assignees

No one assigned

    Labels

    enhancementNew feature or request

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions