runParentPreRun runs the cobra PersistentPreRunE that should fire before this command's own. It first invokes the directly-captured hook (if any) and otherwise walks up the ancestor chain to find the nearest PersistentPreRunE — which matters when the command is nested more than one level deep (e.g.
(cmd *cobra.Command, captured func(*cobra.Command, []string) error, args []string)
| 136 | // parent may have no PersistentPreRunE, but a grandparent (such as |
| 137 | // root) might. |
| 138 | func runParentPreRun(cmd *cobra.Command, captured func(*cobra.Command, []string) error, args []string) error { |
| 139 | if captured != nil { |
| 140 | return captured(cmd, args) |
| 141 | } |
| 142 | for p := cmd.Parent(); p != nil; p = p.Parent() { |
| 143 | if p.PersistentPreRunE != nil { |
| 144 | return p.PersistentPreRunE(cmd, args) |
| 145 | } |
| 146 | } |
| 147 | return nil |
| 148 | } |
| 149 | |
| 150 | // parseModelShorthand parses "provider/model" into a ModelConfig |
| 151 | func parseModelShorthand(s string) *latest.ModelConfig { |