hay-kot / scaffold

A cookie cutter alternative with in-project scaffolding for generating components, controllers, or other common code patterns.
https://hay-kot.github.io/scaffold/
MIT License
51 stars 5 forks source link

Feature request: dynamic messages and default values #174

Open izeau opened 2 months ago

izeau commented 2 months ago

Description:

It'd be awesome if we could use answers from previous questions in our question messages and default values.

Current Limitations:

Right now, all our prompts and defaults are static and can't adapt based on previous answers.

Proposed Changes:

  1. Dynamic Messages: Let us use answers from earlier questions in new question prompts.

    questions:
     - name: player_name
       required: true
       prompt:
         message: What's your name?
    
     - name: player_age
       required: true
       prompt:
         message: And how old are you, {{ .Scaffold.player_name }}?
  2. Dynamic Default Values: Use previous answers to set default values with interpolations.

    questions:
     - name: player_name
       required: true
       prompt:
         message: What's your name?
    
     - name: player_alias
       required: true
       prompt:
         message: Now, pick an alias
         default: |-
           {{ regexReplaceAll "[^a-z]+" (.Scaffold.player_name | lower) "_" }}

Benefits:

What do you think?

hay-kot commented 2 months ago

I like it! Fully support adding this, few things I can offer on the implementation:

  1. I don't know if this would be possible. I'm doing some pretty nargly things to get templating to work for the when field and I don't see a clear way to add support for this. It may require upstream changes in the huh library. - Which is to say, this will probably be more difficult that it initially seems.
  2. Important that we support all types of default values, list of strings is the only other one I can think of.
  3. For the templates for the when field, properties from preview inputs are available at top level ({{ .player_name}} vs {{ .Scaffold.player_name }}) I think this makes sense because none of the other top level properties are available.

Happy to work together to get this done, but my summer is pretty packed so may be gaps between when I can reply!

izeau commented 2 months ago

Hello! It looks like dynamic forms are on the roadmap for huh, but are not available yet. In the meantime they recommend using separate forms, but that kind of breaks the workflow I guess? I think we should wait until this is released :)

Enjoy your summer!