Skip to content

Commit 350c74b

Browse files
committed
docs: mention when Get would be safe to use
1 parent 2b4ebe8 commit 350c74b

1 file changed

Lines changed: 10 additions & 4 deletions

File tree

cli.go

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -204,10 +204,16 @@ func Lookup[T any](c *Command, id string) (T, bool) {
204204
return zero, false
205205
}
206206

207-
// Get gets the parsed input value with the given id in the given Command and converts
208-
// the value to the given type T through an untested type assertion. This function will
209-
// panic if the value isn't found or if the value can't be converted to type T.
210-
// To check whether the value is found instead of panicking, see [Lookup].
207+
// Get gets the parsed input value with the given id in the given Command and converts the
208+
// value to the given type T through an untested type assertion. This function will panic
209+
// if the value isn't found or if the value can't be converted to type T. Therefore, this
210+
// function would typically only be used to retrieve parsed values for inputs that are
211+
// required with (which means there will be a parsing error first if there is no value
212+
// present) or that have a default value specified (which means there will always be at
213+
// least one parsed value no matter what). In those cases, this function will be
214+
// completely safe to use.
215+
//
216+
// To check whether the value is found without panicking if it isn't, see [Lookup].
211217
func Get[T any](c *Command, id string) T {
212218
if v, ok := Lookup[T](c, id); ok {
213219
return v

0 commit comments

Comments
 (0)