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

Feature request: use other input values in default #101

Closed
jamesarosen opened this issue Dec 19, 2022 · 4 comments · Fixed by #112
Closed

Feature request: use other input values in default #101

jamesarosen opened this issue Dec 19, 2022 · 4 comments · Fixed by #112
Labels
enhancement New feature or request

Comments

@jamesarosen
Copy link
Contributor

jamesarosen commented Dec 19, 2022

I'd love to be able to use other input values in the Proc form for default:

input :foo, type: [String], allow_nil: false
input :bar, type: [String], default: ->(inputs) { "Default Bar: #{inputs[:foo]}" }

You probably don't want the Proc to be able to modify inputs, so we should pass a defensive copy:

def default_for_normal_mode_with(result, key, default)
  if default.is_a?(Proc)
    args = []
    args.push(result.dup) if default.arity != 0
    default = default.call(*args)
  end

  result[key] = default
end

If you're interested in this, I'm happy to open a pull request.

@jamesarosen jamesarosen changed the title Use other input values in default Feature request: use other input values in default Dec 19, 2022
@sunny sunny added the enhancement New feature or request label Dec 20, 2022
@sunny
Copy link
Owner

sunny commented Dec 20, 2022

Oh, that could be interesting! Please go for it 👍🏻

Good thinking about the fact that we should be defensive to disallow copies during checks 👏🏻

@sunny
Copy link
Owner

sunny commented Feb 19, 2023

Hi @jamesarosen, would you have some time to open a PR for this?

@jamesarosen
Copy link
Contributor Author

Yes, but it's going to be a week or two before I do.

@sunny
Copy link
Owner

sunny commented Feb 23, 2023

Sounds good to me :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants