(cmd *cobra.Command, args []string)
| 67 | } |
| 68 | |
| 69 | func aiRun(cmd *cobra.Command, args []string) (rtnErr error) { |
| 70 | defer func() { |
| 71 | sendActivity("ai", rtnErr == nil) |
| 72 | }() |
| 73 | |
| 74 | if len(args) == 0 && aiMessageFlag == "" { |
| 75 | OutputHelpMessage(cmd) |
| 76 | return fmt.Errorf("no files or message provided") |
| 77 | } |
| 78 | |
| 79 | const maxFileCount = 15 |
| 80 | const rpcTimeout = 30000 |
| 81 | |
| 82 | var allFiles []wshrpc.AIAttachedFile |
| 83 | var stdinUsed bool |
| 84 | |
| 85 | if len(args) > maxFileCount { |
| 86 | return fmt.Errorf("too many files (maximum %d files allowed)", maxFileCount) |
| 87 | } |
| 88 | |
| 89 | for _, filePath := range args { |
| 90 | var data []byte |
| 91 | var fileName string |
| 92 | var mimeType string |
| 93 | var err error |
| 94 | |
| 95 | if filePath == "-" { |
| 96 | if stdinUsed { |
| 97 | return fmt.Errorf("stdin (-) can only be used once") |
| 98 | } |
| 99 | stdinUsed = true |
| 100 | |
| 101 | data, err = io.ReadAll(os.Stdin) |
| 102 | if err != nil { |
| 103 | return fmt.Errorf("reading from stdin: %w", err) |
| 104 | } |
| 105 | fileName = "stdin" |
| 106 | mimeType = "text/plain" |
| 107 | } else { |
| 108 | fileInfo, err := os.Stat(filePath) |
| 109 | if err != nil { |
| 110 | return fmt.Errorf("accessing file %s: %w", filePath, err) |
| 111 | } |
| 112 | absPath, err := filepath.Abs(filePath) |
| 113 | if err != nil { |
| 114 | return fmt.Errorf("getting absolute path for %s: %w", filePath, err) |
| 115 | } |
| 116 | |
| 117 | if fileInfo.IsDir() { |
| 118 | result, err := fileutil.ReadDir(filePath, 500) |
| 119 | if err != nil { |
| 120 | return fmt.Errorf("reading directory %s: %w", filePath, err) |
| 121 | } |
| 122 | jsonData, err := json.Marshal(result) |
| 123 | if err != nil { |
| 124 | return fmt.Errorf("marshaling directory listing for %s: %w", filePath, err) |
| 125 | } |
| 126 | data = jsonData |
nothing calls this directly
no test coverage detected