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: add ignore command option #144
Conversation
@aerogear/charmil-core |
validator/rules/executor.go
Outdated
func validate(cmd *cobra.Command, info *validator.StatusLog, ruleConfig *RuleConfig, userValidatorConfig *ValidatorConfig) { | ||
|
||
// if command needs to be ignored | ||
if val, ok := userValidatorConfig.ValidatorOptions.IgnoreCommands[cmd.Use]; ok { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
How this will work with nested commands? Do we use .
to map the nested commands.
Example:
kafka.create
registry.create
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
it captures Use
of the command, so
kafka.create
registry.create
all create
subcommands will be ignored. Let's fix this!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
However, would that be hard? Can we simply create method that returns true or false for the current command and rule rule?
EDIT:
Ignore me that will be bad idea.
I think we might need something as follows:
- Ignore entire chain of commands (when you do dev etc.) and still want tests to pass
- Ignore single command in nested scenario for all rules
- Ignore single command in nested scenario for some rule.
Instead of impleentatation I would love to see config you will come up with so we can discuss it.
Remeber - we focus on API and docs first :D
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
for nested/all commands, best way is to use CommandPath() provided by cobra.
user will specify : {"kafka create": true, "echo": true}
This config is coming to my mind atm -
type ValidatorOptions struct {
Verbose bool
SkipChildren map[string]bool
SkipCommands map[string]bool
}
RuleOptions to be present in each rule, for controlling rule specific properties/options
type RuleOptions struct {
Verbose bool
SkipCommands map[string]bool
}
eg -
type Length struct {
RuleOptions validator.RuleOptions
Limits map[string]Limit
}
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
type Length struct {
RuleOptions validator.RuleOptions
Could that be part of the interface so we can still have generic processing and enforce options for each rule
SkipChildren map[string]bool
Not needed/confusing. If you specify command path that is groping other commands all grouped ones will be disabled.
map[string]bool
Not sure if that would give us enough to control command (path to command), rule, level - Error/Ignore (could be warn in the future)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
RuleOptions validator.RuleOptions
Could that be part of the interface so we can still have generic processing and enforce options for each rule
Rules interface?
SkipChildren map[string]bool
Not needed/confusing. If you specify command path that is grouping other commands all grouped ones will be disabled.
can you please provide an example for understanding
map[string]bool
Not sure if that would give us enough to control command (path to command), rule, level - Error/Ignore (could be warn in the future)
do we need all this details, when we ignore some command?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
do we need all this details, when we ignore some command?
Agreed. No need
I'm good to merge this :) after we add documentation |
Yes, but shouldn't these be included as well?
|
You can try adding some quick wins :D |
Ignore CommandsSometimes during development, you want to pass the tests for certain commands, but at the same time use Validator for tests. Validation can be skipped/ignored for the commands, mentioned in the validator configuration.
ValidatorOptions: rules.ValidatorOptions{
SkipCommands: map[string]bool{"cmd100 cmd0 subcmd01": true},
},
ValidatorOptions: rules.ValidatorOptions{
SkipChildren: map[string]bool{"cmd100": true},
},
Length: rules.Length{
RuleOptions: validator.RuleOptions{
SkipCommands: map[string]bool{"cmd100": true},
},
Limits: map[string]rules.Limit{
"Use": {Min: 1},
},
}, |
Length: rules.Length{ | ||
RuleOptions: validator.RuleOptions{ | ||
SkipCommands: map[string]bool{"mycli actions create": true}, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@ankithans is that ok?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
yes.. this looks good!
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
example had only create
command so I wasn't sure if you are using cobra paths for this
Closes #86
Description
IgnoreCommands map[string]bool option in ValidatorOptions, for ignoring validation
Type of change
Checklist