Panic if `AddFlags` does not have a pointer receiver
- Dominant language
- Go
- Stars
- 17
- Forks
- 5
- PR merge metrics
- No merged PRs in 30d
Description
If a user defines an `AddFlags` method which does not have a _pointer receiver_, it will not properly bind the flag to the value on the object but rather an ephemeral memory location. It also is simply not being called at the moment. An example of this causing a problem in syft where the `--key` flag was not bound [can be seen here](https://github.com/anchore/syft/blob/e0e1c4ba0a5ec546692428efce4a3bb9b8bc250d/cmd/syft/internal/options/attest.go#L15). Realistically, this is always a coding problem that needs to be fixed and we should `panic` if we find `AddFlags` methods that were incorrectly specified so a user can more quickly get these fixed; i.e. panic if methods seen like this:
```go
func (o Attest) AddFlags(flags fangs.FlagSet) {
...
}
```
... instead of this:
```go
func (o *Attest) AddFlags(flags fangs.FlagSet) {
...
}
```
Contributor guide
No contributing guide indexed for this repository
Research direction
Start at the AddFlags handling and trace how methods are discovered and invoked, using the syft Attest example as a reproduction. Verify the behavior for value and pointer receivers, then add coverage showing that an incorrectly specified value receiver causes a panic while a pointer receiver binds flags correctly.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- go
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 42/100