Skip to content

Conversation

@Aerex
Copy link
Collaborator

@Aerex Aerex commented Oct 9, 2025

Context

The purpose of this PR is to add validation for the plugin.PluginMetadata struct using struct tags. These tags will validate specific properties on the plugin metadata. They are as follows:

Property Name Validation Rule(s)
PluginMetadata.Name Required
PluginMetadata.Version Required
PluginMetadata.MinCliVersion Required
Must be at least 2.0.0
PluginMetadata.Namespaces[] Required
There must at least be one namespace
PluginMetadata.Namespaces[].Name Required
PluginMetadata.Commands[] Required
There must be at least one command
PluginMetadata.Commands[].Name Required
No command name should be called --version
PluginMetadata.Commands[].Description Required
PluginMetadata.Commands[].Usage + Required
PluginMetadata.Commands[].Flags[].Name Required, if a flag is provided
No UTF-16 characters allowed
PluginMetadata.Commands[].Flags[].Description Required, if a flag is provided

The Validator package was created to provide a public interface for validating and retrieving validation errors on any given plugin metadata. If there are any errors found, an array of ValidationError objects will be returned where each object represents a single violation. A plugin can have multiple violations on its metadata.

Note

+: The usage text will validate against a few basic rules which can be expanded upon in the future. These rules are as follows:

  • Groupings (<, [, [) must be closed
  • No UTF-16 encoded characters in the name
  • No placeholder arguments and flags (eg. [arguments] or [options...]). All arguments and flags should be explicit listed in the usage text
  • No basic usage text that contains just COMMAND (This should be expounded upon in the future but I have seen this prevalent in current plugins)

In addition, the Plugin Developer Guide has been updated to include more details on what is required and optional when defining a plugin metadata.

@Aerex Aerex requested a review from steveclay as a code owner October 9, 2025 21:59
toolchain go1.24.4

require (
github.com/Masterminds/semver v1.5.0
Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Callout: Used to validate against the provided min CLI version defined in the metadata and the allowed min CLI version. The package is used in the core CLI.

@Aerex Aerex force-pushed the feat/plugin-metadata-linter branch from 49639c2 to 47399b3 Compare October 9, 2025 22:07
github.com/Masterminds/semver v1.5.0
github.com/fatih/color v1.7.1-0.20180516100307-2d684516a886
github.com/fatih/structs v1.0.1-0.20171020064819-f5faa72e7309
github.com/go-playground/validator/v10 v10.28.0
Copy link
Collaborator Author

@Aerex Aerex Oct 9, 2025

Choose a reason for hiding this comment

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

Callout: This package is validation library to support validation using struct tags.

Widely used package under the MIT license. Over 200+ contributors and the last release was 4 days ago.

@Aerex Aerex force-pushed the feat/plugin-metadata-linter branch from 47399b3 to 2d399b4 Compare October 9, 2025 22:16
@Aerex Aerex force-pushed the feat/plugin-metadata-linter branch from 2d399b4 to 7243b11 Compare October 14, 2025 21:56
- _Commands_: The array of `plugin.Commands` to register the plug-in commands.
- _Alias_: Alias of the Alias usually is a short name of the command.
- _Command.Flags_: The command flags (options) which will be displayed as a part of help output of the command.
- _Alias_ (*optional*): Alias of the Alias usually is a short name of the command.
Copy link
Collaborator

Choose a reason for hiding this comment

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

Alias of the Alias does not make sense. This pre-existed this PR.

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah let me fix that here.

Namespace string // full qualified name of the command's namespace
Name string // name of the command
Namespace string `validate:"required"` // full qualified name of the command's namespace
Name string `validate:"required,ne=--version"` // name of the command
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this a work-around? --version was being interpreted as a command name?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah it was. We need to tell the plug-in devs to remove that as a command.

plugin/plugin.go Outdated
type Flag struct {
Name string // name of the option
Description string // description of the option
Name string `validate:"required,excludesall=<>"` // name of the option
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you give an example where this is necessary?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yeah I will add that as comment here. Basically, it prevents flag names like <invalidValue> which is not correct.

return err.Error()
}
case "mincliversion":
if err := validateCliVersionMinimum(fieldErr.Value().(VersionType), fieldErr.Param()); err != nil {
Copy link
Collaborator

Choose a reason for hiding this comment

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

So, in the case of mincliversion, fieldErr.Param() will be the minimum value of core CLI allowed (2.0.0)?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Correct

if minErr != nil {
return minErr
}
specifiedVersion, verErr := semver.NewVersion(versionType.String())
Copy link
Collaborator

Choose a reason for hiding this comment

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

specifiedVersion is the min core CLI version the plug-in has defined in its metadata?

Copy link
Collaborator Author

Choose a reason for hiding this comment

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

Yes

@steveclay
Copy link
Collaborator

@Aerex Please see the questions above, otherwise looking great.

@Aerex Aerex requested a review from steveclay October 22, 2025 15:15
@steveclay steveclay merged commit 562585d into dev Oct 22, 2025
@steveclay steveclay deleted the feat/plugin-metadata-linter branch October 22, 2025 16:55
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