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

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

Open
wants to merge 3 commits into
base: main
Choose a base branch
from

Conversation

vahnrr
Copy link

@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

confirm/command.go Show resolved Hide resolved
Comment on lines 39 to 53
} 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
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?

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.

2 participants