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

Don't always add default values #441

Merged
merged 12 commits into from
Oct 18, 2023
Merged

Don't always add default values #441

merged 12 commits into from
Oct 18, 2023

Conversation

crhntr
Copy link
Contributor

@crhntr crhntr commented Sep 8, 2023

Kiln currently will behave strangely when an options structure has multiple lists of string fields. Jhanda adds default flag values even when flags are passed. Kiln trims these additional defaults off when a user passes any flags that match that field. There was an error in the logic where it would return early and not trim defaults on fields after the first configured list.

type Command struct {
  Options struct{
    ListA []string `short:"a" default:"apple"`
    ListB []string `short:"b" default:"banana"`
  }
}

Given the above struct,
if you ran cmd -a=apricot -b=bean,
then you'd experience cmd -a=apricot -b=banana -b=bean

I finally found and fixed a bug here a5bd61f. The rest of the commits were small refactors/improvements that I found along the way.

The commits headers were written to be read. I decided not to squash these changes to make review easier. The hunt for the bug was chaotic and I feel this is safe to ship in a patch release.

@cf-gitbot
Copy link
Member

We have created an issue in Pivotal Tracker to manage this. Unfortunately, the Pivotal Tracker project is private so you may be unable to view the contents of the story.

The labels on this github issue will be updated when the story is started.

@crhntr crhntr changed the title fix(bake): default file paths are sometimes still used even when the paths don't exist Only use a default path if it exists on disk Oct 5, 2023
@crhntr crhntr changed the title Only use a default path if it exists on disk Only use a default path if it exists Oct 5, 2023
@crhntr crhntr changed the title Only use a default path if it exists Don't always add default values Oct 5, 2023
Copy link
Contributor

@pabloarodas pabloarodas left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Sorry for the delay in reviewing it, It took me long enough to understand the changes.

@pabloarodas pabloarodas merged commit 19ccbc1 into main Oct 18, 2023
3 checks passed
@pabloarodas pabloarodas deleted the fix-bake-flag-weirdness branch October 18, 2023 16:12
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants