Skip to content

feat(confirm): add --show-output #427

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

Merged
merged 2 commits into from
Dec 12, 2024

Conversation

vahnrr
Copy link
Contributor

@vahnrr vahnrr commented Sep 18, 2023

Fixes nothing, this is a feature I found missing from a specific use case I had in mind.

Changes

Adds the --show-output flag to gum confirm which prints the prompt and the chosen action to STDOUT.

gum confirm --show-output 'Do you agree?'
# Do you agree? Yes

gum confirm --show-output 'Do you agree?'
# Do you agree? No
# exit status 1

This merge adds 2 commits, only the first one (4f9235b) is required for the feature to work.
Since the feature doesn't affect confirm/confirm.go I feel like the second (432182f) isn't necessary, but I still included it in case I misunderstood the purpose of the model structure.

Copy link
Contributor

@MikaelFangel MikaelFangel left a comment

Choose a reason for hiding this comment

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

I have added some suggestions to help fix your linting error.

Also, you can check if it passes linting before pushing by using golangci-lint run

Comment on lines 39 to 48
} else {
os.Exit(1)
if o.ShowOutput {
confirmationText := m.(model).negative
if m.(model).confirmation {
confirmationText = m.(model).affirmative
}
fmt.Println(m.(model).prompt, confirmationText)
}

if m.(model).confirmation {
os.Exit(0)
} else {
os.Exit(1)
}
}
Copy link
Contributor

Choose a reason for hiding this comment

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

Here you should remove the else and outdent the code and also the last else statement can be outdented as well.

The code will look something like this.

	}

	if o.ShowOutput {
		confirmationText := m.(model).negative
		if m.(model).confirmation {
			confirmationText = m.(model).affirmative
		}
		fmt.Println(m.(model).prompt, confirmationText)
	}

	if m.(model).confirmation {
		os.Exit(0)
	}

	os.Exit(1)

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I must have missed the CI result notifications, really sorry.
This should be fixed as per you suggestions, thanks!

Regarding the model structure, do you think this commit is necessary?

@caarlos0
Copy link
Member

this looks good! can you fix the conflicts? if not, I can re-implement it on main...

@vahnrr vahnrr force-pushed the confirm-show-output branch from 2bb47ec to 3d74294 Compare December 12, 2024 18:35
@vahnrr
Copy link
Contributor Author

vahnrr commented Dec 12, 2024

No problem, it should be up to date now

@caarlos0 caarlos0 merged commit d1bfd56 into charmbracelet:main Dec 12, 2024
7 checks passed
@caarlos0
Copy link
Member

thanks @vahnrr

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

Successfully merging this pull request may close these issues.

3 participants