MCPcopy Create free account
hub / github.com/dim-an/cod / runHelpCommand

Method runHelpCommand

server/server.go:463–501  ·  view source on GitHub ↗
(command datastore.Command, ctx context.Context)

Source from the content-addressed store, hash-verified

461}
462
463func (s *serverImpl) runHelpCommand(command datastore.Command, ctx context.Context) (helpPage *datastore.HelpPage, err error) {
464 if len(command.Args) == 0 {
465 err = fmt.Errorf("command is empty")
466 return
467 }
468
469 executablePath, err := datastore.CanonizeExecutablePath(
470 command.Args[0],
471 command.Dir,
472 util.GetPathVar(command.Env),
473 util.GetHomeVar(command.Env),
474 )
475
476 if err != nil {
477 return
478 }
479
480 argv := command.Args
481 argv[0] = executablePath
482
483 cmd := exec.CommandContext(ctx, executablePath)
484 cmd.Args = argv
485 cmd.Env = command.Env
486 cmd.Dir = command.Dir
487 cmd.Stdin = nil
488
489 helpBytes, err := cmd.CombinedOutput()
490 if err != nil {
491 err = fmt.Errorf("%w: %v", err, string(helpBytes))
492 return
493 }
494 helpPage, err = parse_doc.ParseHelp(argv, string(helpBytes))
495 if err != nil {
496 return
497 }
498 helpPage.Command = command
499
500 return
501}
502
503func (s *serverImpl) handleAddHelpPage(req *AddHelpPageRequest, _ *util.Warner) (rsp AddHelpPageResponse, err error) {
504 ctx, _ := context.WithTimeout(context.Background(), HelpProcessExecutionTimeout)

Callers 2

handleAddHelpPageMethod · 0.95

Calls 4

CanonizeExecutablePathFunction · 0.92
GetPathVarFunction · 0.92
GetHomeVarFunction · 0.92
ParseHelpFunction · 0.92

Tested by

no test coverage detected