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

Refactor watchdtui using the new bubbles Validate API #375

Closed
GabrielNagy opened this issue Jul 5, 2022 · 2 comments
Closed

Refactor watchdtui using the new bubbles Validate API #375

GabrielNagy opened this issue Jul 5, 2022 · 2 comments
Assignees
Labels
enhancement New feature or request jira Import to Jira

Comments

@GabrielNagy
Copy link
Contributor

Describe the problem you'd like to have solved

The new bubbles release comes with a Validate API which we can use to validate our TUI inputs (directories and config file). Currently, validation is done via arbitrary functions that directly operate on the textinput.Model objects, e.g.

// updateConfigInputError updates the error state of the config input.
func updateConfigInputError(input *textinput.Model) {
value := input.Value()
// If the config input is empty, clean up the error message
if value == "" {
input.Err = nil
return
}
absPath, _ := filepath.Abs(value)
stat, err := os.Stat(value)
// If the config file does not exist, we're good
if errors.Is(err, os.ErrNotExist) {
input.Err = nil
if !filepath.IsAbs(value) {
input.Err = fmt.Errorf(i18n.G("%s will be the absolute path"), absPath)
}
return
}
// If we got another error, display it
if err != nil {
input.Err = err
return
}
if stat.IsDir() {
input.Err = fmt.Errorf(i18n.G("%s is a directory; will create %s.yaml inside"), absPath, watchdconfig.CmdName)
return
}
if stat.Mode().IsRegular() {
input.Err = fmt.Errorf(i18n.G("%s: file already exists and will be overwritten"), absPath)
return
}
input.Err = nil
}

Describe the ideal solution

Input validation is done via the newly added API.

@GabrielNagy GabrielNagy self-assigned this Jul 5, 2022
@GabrielNagy GabrielNagy added enhancement New feature or request jira Import to Jira labels Jul 5, 2022
@GabrielNagy
Copy link
Contributor Author

GabrielNagy commented Jul 11, 2022

I have a branch up for this refactor -- based on top of charmbracelet/bubbles#185

@jibel
Copy link
Collaborator

jibel commented Nov 30, 2023

Fixed with 1f819dc

@jibel jibel closed this as completed Nov 30, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request jira Import to Jira
Projects
None yet
Development

No branches or pull requests

2 participants