Replies: 3 comments 2 replies
-
First Solution
We can ease this for developers by creating code generator type options struct {
Use string
Short string
Long string
}
func validateOptions(opts options) error {
if len(opts.Short) <= 2 {
return fmt.Errorf("length of short should be atleast greater than 2")
}
if len(opts.Long) <= 5 {
return fmt.Errorf("length of long should be atleast greater than 5")
}
return nil
}
// main
testOpts := &options{
Use: "root",
Short: "r",
Long: "root the long string as it should be long so let's test it!",
}
err := validateOptions(*testOpts)
if err != nil {
panic(err)
}
cmd := &cobra.Command{
Use: testOpts.Use,
Short: testOpts.Short,
Long: testOpts.Long,
} |
Beta Was this translation helpful? Give feedback.
-
Second Solution WIPhttps://github.com/ankithans/cobra-linter |
Beta Was this translation helpful? Give feedback.
-
@ankithans you went far ahead with this with both approaches. See: https://golangci-lint.run/contributing/new-linters/ As for the approach - we kinda need static analysis rather than code analysis - unless we can think of some clever way to do it at runtime As for the AST processor. I do not think we need to go that far as we not going to actually validate golang codebase but can simply operate on cobra structures. (that will be an argument against using golang cli lint) First we need to define set of linting rules we want to apply:
I think we need also simplicity of defining linting rules as well. So if charmil integrator has some rule on cobra command structure @aerogear/charmil-core |
Beta Was this translation helpful? Give feedback.
-
related to issue #58
Beta Was this translation helpful? Give feedback.
All reactions