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

Merge with default values doesn't work on cy create-stackforms-env #281

Open
fhacloid opened this issue Jul 9, 2024 · 1 comment
Open

Comments

@fhacloid
Copy link
Contributor

fhacloid commented Jul 9, 2024

When creating a project using the new stackforms command cy create-stackforms-env -> create-env.go I added logic to fetch the defaults values first to merge them with the values provided by the user.

The merge doesn't happend because the lib i'm using (mergo) can merge only 2 similar structs.

On this line:

		mergo.Merge(&vars, defaultValues, mergo.WithOverride)

The DefaultValues are recovered from the common.ParseFormsConfig() function that take a *model.FormUseCase and return a map[string]map[string]map[string]any (which is the format expected for a vars input for stackforms).

The vars variable is a map[string]interface{} and so, since it's not the same type as DefaultValues it doesn't merge the values.

We need to use the same types for both, this means changing the vars type, but it will require to refactor the common.UpdateMapField() function that is used to apply the -V args. This function is also related to this issue.

@kerak19
Copy link
Contributor

kerak19 commented Jul 15, 2024

It'd be nice to also look into https://github.com/darccio/mergo?tab=readme-ov-file#transformers to see if it can be done by writing our own transformer

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