-
Notifications
You must be signed in to change notification settings - Fork 24
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: Allow passing unknown flags to plugins #1902
Conversation
The way I see it, we can add new properties to the spec without breaking existing plugins, so this should be the same |
Not sure why |
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.
Can we make it log a warning with the unhandled/unknown flag?
I can see if Cobra exposes the unknown flags |
Yeah this seems a bit controversial, as the plugin may silently fail to act as you instructed it to act, which might be worse than failing hard |
I think we should also add an |
Actually @hermanschaaf has a really good point here cc @erezrokah I encountered this many times across the years. You misspell a flag and don't notice and suddenly your tool misbehaves and you find out the week after 🤔 I think this needs some thinking. Because forwards/backwards compatibility is important too. |
Yeah I think this is mostly an internal problem for us, less for our users. |
Maybe we can turn this around, by adding an |
We need spf13/pflag#199, spf13/cobra#739 (comment) |
I like that idea but it needs to be an environment variable (it needs to be evaluated before parsing happens), so maybe when the CLI starts plugins it can pass |
@erezrokah why? Maybe I'm missing something. I know users don't typically run plugins directly, but I still think it's everyone's problem. Let's say we added a new feature to the CLI to allowlist only connections to certain domains (to use a random example). If this is to be enforced by the plugin, it would need to be passed as a flag. With the change here, if users enabled this feature in the CLI, they would expect it to work, but actually it would not, if they are using an older version of a plugin. |
Ah, good point. @marianogappa and I discussed this problem via DMs as well. At the moment the CLI does not know which features plugins support. For example not all plugins support So maybe what we really need is a way for plugins to tell the CLI the features they support |
Even with a warning I think it's problematic. Older version of a plugin is one case, but misspelling is another, am I the only one who misspells a lot? |
My idea was to parse everything twice, once with cobra.Unknown enabled, to detect the unknown flag, and then a second time... but I like this env var idea. |
Move most things to spec, then we can have a message through GRPC? Simplify Also this needs to be accomodated in other language SDKs as well, so moving more things into spec is beneficial from SDK maintenance PoV. |
Well if you init OTEL after spec is parsed, you're bound to miss some logs. But regardless plugins don't have access to top level spec, so we'd need to pass everything to the init gRPC call I think |
Yes the options would be in the outer spec which gets passed into Init (or capability detection call first, then selectively to Init) |
OK going to close this since this warrants an offline discussion |
Summary
Should help with https://github.com/cloudquery/cloudquery-issues/issues/2455#issuecomment-2363343665 (internal issue).
At the moment, each time we add a new flag to a plugin and pass it from the CLI it will break all existing plugins since they fail to parse known flags.
This should allow the CLI send new flags to new plugins without breaking existing ones
Use the following steps to ensure your PR is ready to be reviewed
go fmt
to format your code 🖊golangci-lint run
🚨 (install golangci-lint here)