entrypointCall is executed when it's the first command in a pipeline
(ctx context.Context, cmd string, args []string)
| 339 | |
| 340 | // entrypointCall is executed when it's the first command in a pipeline |
| 341 | func (h *shellCallHandler) entrypointCall(ctx context.Context, cmd string, args []string) (*ShellState, error) { |
| 342 | if cmd, _ := h.BuiltinCommand(cmd); cmd != nil { |
| 343 | return nil, cmd.Execute(ctx, h, args, nil) |
| 344 | } |
| 345 | |
| 346 | st, err := h.StateLookup(ctx, cmd) |
| 347 | if err != nil { |
| 348 | return nil, err |
| 349 | } |
| 350 | if h.Debug() { |
| 351 | shellDebug(ctx, "Entrypoint", cmd, args, st) |
| 352 | } |
| 353 | |
| 354 | def := h.GetDef(st) |
| 355 | |
| 356 | // Command is a function in current context (module or core) |
| 357 | if h.isCurrentContextFunction(cmd) { |
| 358 | // When MainObject is Query (entrypoint proxy or core-only), |
| 359 | // functions are already on Query - no constructor needed. |
| 360 | if def.MainObject.AsObject != nil && def.MainObject.AsObject.Name == "Query" { |
| 361 | newSt := h.NewState() |
| 362 | return h.functionCall(ctx, &newSt, cmd, args) |
| 363 | } |
| 364 | // We need to assume a constructor call without arguments |
| 365 | st, err := h.constructorCall(ctx, def, st, nil) |
| 366 | if err != nil { |
| 367 | return nil, err |
| 368 | } |
| 369 | return h.functionCall(ctx, st, cmd, args) |
| 370 | } |
| 371 | |
| 372 | // Command is a module ref — invoke its named constructor on Query. |
| 373 | if def.HasModule() && st.IsEmpty() && def.ModuleConstructor() != nil { |
| 374 | return h.constructorCall(ctx, def, st, args) |
| 375 | } |
| 376 | |
| 377 | return st, nil |
| 378 | } |
| 379 | |
| 380 | func (h *shellCallHandler) isCurrentContextFunction(name string) bool { |
| 381 | def := h.GetDef(nil) |
no test coverage detected