kubo/core/commands/extra.go
Marcin Rataj 6a008fc74c
refactor: apply go fix modernizers from Go 1.26 (#11190)
* chore: apply go fix modernizers from Go 1.26

automated refactoring: interface{} to any, slices.Contains,
and other idiomatic updates.

* feat(ci): add `go fix` check to Go analysis workflow

ensures Go 1.26 modernizers are applied, fails CI if `go fix ./...`
produces any changes (similar to existing `go fmt` enforcement)
2026-02-11 01:01:32 +01:00

68 lines
1.6 KiB
Go

package commands
import (
cmds "github.com/ipfs/go-ipfs-cmds"
)
func CreateCmdExtras(opts ...func(e *cmds.Extra)) *cmds.Extra {
e := new(cmds.Extra)
for _, o := range opts {
o(e)
}
return e
}
type doesNotUseRepo struct{}
func SetDoesNotUseRepo(val bool) func(e *cmds.Extra) {
return func(e *cmds.Extra) {
e.SetValue(doesNotUseRepo{}, val)
}
}
func GetDoesNotUseRepo(e *cmds.Extra) (val bool, found bool) {
return getBoolFlag(e, doesNotUseRepo{})
}
// doesNotUseConfigAsInput describes commands that do not use the config as
// input. These commands either initialize the config or perform operations
// that don't require access to the config.
//
// pre-command hooks that require configs must not be run before these
// commands.
type doesNotUseConfigAsInput struct{}
func SetDoesNotUseConfigAsInput(val bool) func(e *cmds.Extra) {
return func(e *cmds.Extra) {
e.SetValue(doesNotUseConfigAsInput{}, val)
}
}
func GetDoesNotUseConfigAsInput(e *cmds.Extra) (val bool, found bool) {
return getBoolFlag(e, doesNotUseConfigAsInput{})
}
// preemptsAutoUpdate describes commands that must be executed without the
// auto-update pre-command hook
type preemptsAutoUpdate struct{}
func SetPreemptsAutoUpdate(val bool) func(e *cmds.Extra) {
return func(e *cmds.Extra) {
e.SetValue(preemptsAutoUpdate{}, val)
}
}
func GetPreemptsAutoUpdate(e *cmds.Extra) (val bool, found bool) {
return getBoolFlag(e, preemptsAutoUpdate{})
}
func getBoolFlag(e *cmds.Extra, key any) (val bool, found bool) {
var ival any
ival, found = e.GetValue(key)
if !found {
return false, false
}
val = ival.(bool)
return val, found
}