MCPcopy Create free account
hub / github.com/cogentcore/core / cmdFromCmdOrFunc

Function cmdFromCmdOrFunc

cli/cmd.go:84–93  ·  view source on GitHub ↗

cmdFromCmdOrFunc returns a new [Cmd] object from the given [CmdOrFunc] object, using [cmdFromFunc] if it is a function.

(cmd C)

Source from the content-addressed store, hash-verified

82// cmdFromCmdOrFunc returns a new [Cmd] object from the given
83// [CmdOrFunc] object, using [cmdFromFunc] if it is a function.
84func cmdFromCmdOrFunc[T any, C CmdOrFunc[T]](cmd C) (*Cmd[T], error) {
85 switch c := any(cmd).(type) {
86 case *Cmd[T]:
87 return c, nil
88 case func(T) error:
89 return cmdFromFunc(c)
90 default:
91 panic(fmt.Errorf("internal/programmer error: cli.CmdFromCmdOrFunc: impossible type %T for command %v", cmd, cmd))
92 }
93}
94
95// CmdsFromCmdOrFuncs is a helper function that returns a slice
96// of command objects from the given slice of [CmdOrFunc] objects,

Callers

nothing calls this directly

Calls 2

cmdFromFuncFunction · 0.85
ErrorfMethod · 0.65

Tested by

no test coverage detected