(req suggestions.AutoCompleteRequest)
| 417 | } |
| 418 | |
| 419 | func (m *CLIBridgeModule) onAutoComplete(req suggestions.AutoCompleteRequest) suggestions.AutoCompleteRequest { |
| 420 | if req.Cmd != `cli` { |
| 421 | return req |
| 422 | } |
| 423 | |
| 424 | if len(req.Parts) == 2 { |
| 425 | toolPrefix := strings.ToLower(req.Parts[1]) |
| 426 | for _, tool := range m.getAllowedTools() { |
| 427 | if strings.HasPrefix(strings.ToLower(tool), toolPrefix) { |
| 428 | req.Results = append(req.Results, tool[len(toolPrefix):]) |
| 429 | } |
| 430 | } |
| 431 | return req |
| 432 | } |
| 433 | |
| 434 | if len(req.Parts) < 3 { |
| 435 | return req |
| 436 | } |
| 437 | |
| 438 | partial := req.Parts[len(req.Parts)-1] |
| 439 | dataDir := configs.GetFilePathsConfig().DataFiles.String() |
| 440 | |
| 441 | var searchDir string |
| 442 | var prefix string |
| 443 | |
| 444 | if partial == `` || strings.HasSuffix(partial, `/`) { |
| 445 | searchDir = filepath.Join(dataDir, partial) |
| 446 | prefix = `` |
| 447 | } else { |
| 448 | searchDir = filepath.Join(dataDir, filepath.Dir(partial)) |
| 449 | prefix = strings.ToLower(filepath.Base(partial)) |
| 450 | } |
| 451 | |
| 452 | entries, err := os.ReadDir(searchDir) |
| 453 | if err != nil { |
| 454 | return req |
| 455 | } |
| 456 | |
| 457 | for _, entry := range entries { |
| 458 | name := entry.Name() |
| 459 | if !strings.HasPrefix(strings.ToLower(name), prefix) { |
| 460 | continue |
| 461 | } |
| 462 | suffix := name[len(prefix):] |
| 463 | if entry.IsDir() { |
| 464 | suffix += `/` |
| 465 | } |
| 466 | req.Results = append(req.Results, suffix) |
| 467 | } |
| 468 | |
| 469 | return req |
| 470 | } |
| 471 | |
| 472 | func (m *CLIBridgeModule) stopSession(sess *Session) { |
| 473 | sess.mu.Lock() |
nothing calls this directly
no test coverage detected