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

Add command validation #8

Merged
merged 9 commits into from
Feb 15, 2024
Merged

Add command validation #8

merged 9 commits into from
Feb 15, 2024

Conversation

dadgar
Copy link
Collaborator

@dadgar dadgar commented Feb 14, 2024

This PR adds command validation to codify many formatting guidelines. It also deprecates unused fields in command Examples.

Moving forward command validation will be run as a test to avoid non-conventional commands from being added.

Would suggest reviewing the PR commit by commit.

Deprecate the Example Title and Postamble. It ended up not really being
used and makes formating simpler in the case where some examples have
titles and others do not.

Add validation to enforce that the preamble starts with a capital and
ends with a colon. Update all commands to follow this format.
Copy link
Contributor

@tobias-hashicorp tobias-hashicorp 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.

⌛ I wonder if it would be helpful to collect all errors instead of returning only the first. It could make it a bit easier to fix all problems in one swoop instead of having to rerun the tests multiple times.


I am using Feedback Ladder annotations to make the importance/urgency of comments easier to understand.

Emoji Name Importance/Urgency
🏔 Mountain This change should not go live. Back to the drawing board.
🧗🏻‍♂️ Boulder Has to be addressed before this can be merged.
⚪️ Pebble Needs to be addressed. Can be in a future PR.
Sand Needs to be considered. Can be in a future PR.
✏️ Pen Typo or grammatical error. Can be addressed in a future PR.
💨 Dust "Take it or Leave it"

internal/pkg/cmd/validate.go Outdated Show resolved Hide resolved
internal/pkg/cmd/validate.go Show resolved Hide resolved
internal/pkg/cmd/validate.go Outdated Show resolved Hide resolved
internal/pkg/cmd/validate.go Outdated Show resolved Hide resolved

// Check for duplicates
if _, ok := aliases[alias]; ok {
return fmt.Errorf("duplicate alias %q found", alias)
Copy link
Contributor

Choose a reason for hiding this comment

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

💨 The error messages switch between stating what is wrong "duplicate alias %q found" and stating what is allowed/not allowed "command name cannot be an alias". I think it would be good to be consistent and always state what is not allowed "alias %q: aliases can not be duplicated" (or "alias can not be empty" below).

}

// Validate that the help text is set
if c.ShortHelp == "" || c.LongHelp == "" {
Copy link
Contributor

Choose a reason for hiding this comment

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

💨 It could be helpful to have these as two checks with different error messages.

internal/pkg/cmd/validate_test.go Outdated Show resolved Hide resolved
Comment on lines +269 to +273
if e.Command == "" {
return fmt.Errorf("command cannot be empty")
} else if !strings.HasPrefix(e.Command, "$ ") {
return fmt.Errorf("example command must start with $")
}
Copy link
Contributor

Choose a reason for hiding this comment

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

⌛ Should we validate that newlines are prefixed with a \?

internal/pkg/cmd/validate.go Show resolved Hide resolved
@dadgar dadgar merged commit 7c6acdb into main Feb 15, 2024
2 checks passed
@dadgar dadgar deleted the f-command-validation branch February 15, 2024 00:01
teresamychu pushed a commit that referenced this pull request Feb 22, 2024
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