(command string)
| 117 | } |
| 118 | |
| 119 | func (cli *ChatCLI) executeDirectCommand(command string) { |
| 120 | fmt.Println(i18n.T("command.executing"), command) |
| 121 | |
| 122 | // Verificar se o comando é interativo |
| 123 | isInteractive := false |
| 124 | if strings.HasPrefix(command, "-i ") || strings.HasPrefix(command, "--interactive ") { |
| 125 | isInteractive = true |
| 126 | // Remover a flag do comando |
| 127 | command = strings.TrimPrefix(command, "-i ") |
| 128 | command = strings.TrimPrefix(command, "--interactive ") |
| 129 | } |
| 130 | |
| 131 | // Verificar se o comando contém a flag --send-ai e pipe | |
| 132 | sendToAI := false |
| 133 | var aiContext string |
| 134 | if strings.Contains(command, "-ai") { |
| 135 | sendToAI = true |
| 136 | // Remover a flag do comando |
| 137 | command = strings.Replace(command, "-ai", "", 1) |
| 138 | } |
| 139 | |
| 140 | // Verificar se há um maior > no comando |
| 141 | if strings.Contains(command, ">") { |
| 142 | parts := strings.Split(command, ">") |
| 143 | command = strings.TrimSpace(parts[0]) |
| 144 | aiContext = strings.TrimSpace(parts[1]) |
| 145 | } |
| 146 | |
| 147 | // Obter o shell do usuário |
| 148 | userShell := utils.GetUserShell() |
| 149 | shellPath, err := exec.LookPath(userShell) |
| 150 | if err != nil { |
| 151 | cli.logger.Error("Erro ao localizar o shell", zap.Error(err)) |
| 152 | fmt.Println(i18n.T("command.error.shell_not_found"), err) |
| 153 | return |
| 154 | } |
| 155 | |
| 156 | // Obter o caminho do arquivo de configuração do shell |
| 157 | shellConfigPath := utils.GetShellConfigFilePath(userShell) |
| 158 | if shellConfigPath == "" { |
| 159 | fmt.Println(i18n.T("command.error.shell_config_not_found"), userShell) |
| 160 | return |
| 161 | } |
| 162 | |
| 163 | // Construir o comando para carregar o arquivo de configuração e executar o comando do usuário |
| 164 | shellCommand := fmt.Sprintf("source %s && %s", utils.ShellQuote(shellConfigPath), command) |
| 165 | |
| 166 | cmd := exec.Command(shellPath, "-c", shellCommand) //#nosec G204 -- agent/CLI tool execution; commands validated by command_validator + policy_manager upstream |
| 167 | |
| 168 | if isInteractive { |
| 169 | fmt.Println(i18n.T("command.warning.interactive")) |
| 170 | cmd.Stdin = os.Stdin |
| 171 | cmd.Stdout = os.Stdout |
| 172 | cmd.Stderr = os.Stderr |
| 173 | err = cmd.Run() |
| 174 | if err != nil { |
| 175 | fmt.Println(i18n.T("command.error.execution"), err) |
| 176 | } |
no test coverage detected