()
| 281 | } |
| 282 | |
| 283 | func (h *shellCallHandler) registerCommands() error { //nolint:gocyclo |
| 284 | var builtins []*ShellCommand |
| 285 | |
| 286 | builtins = append(builtins, |
| 287 | &ShellCommand{ |
| 288 | Use: ".debug", |
| 289 | Hidden: true, |
| 290 | Args: NoArgs, |
| 291 | State: NoState, |
| 292 | Run: func(_ context.Context, _ *ShellCommand, _ []string, _ *ShellState) error { |
| 293 | // Toggles debug mode, which can be useful when in interactive mode |
| 294 | // while developing or troubleshooting what happens in each step |
| 295 | h.mu.Lock() |
| 296 | h.debug = !h.debug |
| 297 | h.mu.Unlock() |
| 298 | return nil |
| 299 | }, |
| 300 | }, |
| 301 | &ShellCommand{ |
| 302 | Use: ".help [command | function | module | type]\n<function> | .help [function]", |
| 303 | Description: `Show documentation for a command, function, module, or type`, |
| 304 | Args: MaximumArgs(1), |
| 305 | Run: func(ctx context.Context, cmd *ShellCommand, args []string, st *ShellState) error { |
| 306 | var err error |
| 307 | |
| 308 | // First command in chain |
| 309 | if st == nil { |
| 310 | if len(args) == 0 { |
| 311 | // No arguments, e.g, `.help`. |
| 312 | return h.Print(ctx, h.MainHelp()) |
| 313 | } |
| 314 | |
| 315 | // Check builtins first |
| 316 | if c, _ := h.BuiltinCommand(args[0]); c != nil { |
| 317 | return h.Print(ctx, c.Help()) |
| 318 | } |
| 319 | |
| 320 | // Check if a type before handing off to state lookup |
| 321 | if t := h.GetDef(nil).GetTypeDef(args[0]); t != nil { |
| 322 | return h.Print(ctx, shellTypeDoc(t)) |
| 323 | } |
| 324 | |
| 325 | // "." and the current module name refer to this module. |
| 326 | if def := h.GetDef(nil); def.HasModule() && (args[0] == "." || args[0] == def.Name) { |
| 327 | return h.Print(ctx, h.ModuleDoc(def)) |
| 328 | } |
| 329 | |
| 330 | // Use the same function lookup as when executing |
| 331 | // so that `> .help wolfi` documents `> wolfi`. |
| 332 | st, err = h.StateLookup(ctx, args[0]) |
| 333 | if err != nil { |
| 334 | return err |
| 335 | } |
| 336 | if st.ModDigest != "" { |
| 337 | // First argument to `.help` is a module reference, so |
| 338 | // remove it from list of arguments now that it's loaded. |
| 339 | // The rest of the arguments should be passed on to |
| 340 | // the constructor. |
no test coverage detected