MCPcopy Create free account
hub / github.com/diillson/chatcli / completeFilePath

Method completeFilePath

cli/cli_completer.go:495–529  ·  view source on GitHub ↗

completeFilePath autocompleta caminhos de arquivos

(prefix string)

Source from the content-addressed store, hash-verified

493
494// completeFilePath autocompleta caminhos de arquivos
495func (cli *ChatCLI) completeFilePath(prefix string) []string {
496 var completions []string
497
498 dir, filePrefix := filepath.Split(prefix)
499 if dir == "" {
500 dir = "."
501 }
502
503 // Expandir "~" para o diretório home
504 dir = os.ExpandEnv(dir)
505 if strings.HasPrefix(dir, "~") {
506 homeDir, err := os.UserHomeDir()
507 if err == nil {
508 dir = filepath.Join(homeDir, dir[1:])
509 }
510 }
511
512 files, err := os.ReadDir(dir)
513 if err != nil {
514 return completions
515 }
516
517 for _, entry := range files {
518 name := entry.Name()
519 if strings.HasPrefix(name, filePrefix) {
520 path := filepath.Join(dir, name)
521 if entry.IsDir() {
522 path += string(os.PathSeparator)
523 }
524 completions = append(completions, path)
525 }
526 }
527
528 return completions
529}
530
531// completeSystemCommands autocompleta comandos do sistema
532func (cli *ChatCLI) completeSystemCommands(prefix string) []string {

Callers 1

filePathCompleterMethod · 0.95

Calls 1

NameMethod · 0.65

Tested by

no test coverage detected