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

Method simulateCommandBlock

cli/agent_command_blocks.go:947–983  ·  view source on GitHub ↗

simulateCommandBlock simula execução (dry-run)

(ctx context.Context, block agent.CommandBlock)

Source from the content-addressed store, hash-verified

945
946// simulateCommandBlock simula execução (dry-run)
947func (a *AgentMode) simulateCommandBlock(ctx context.Context, block agent.CommandBlock) {
948 fmt.Printf(i18n.T("agent.status.simulating_commands", block.Language)+"\n", block.Language)
949 fmt.Println("---------------------------------------")
950
951 shell := os.Getenv("SHELL")
952 if shell == "" {
953 shell = "/bin/sh"
954 }
955
956 for i, cmd := range block.Commands {
957 if cmd == "" {
958 continue
959 }
960 fmt.Printf("🔸 %s %d/%d: %s\n", i18n.T("agent.dryrun.label"), i+1, len(block.Commands), cmd)
961
962 simCmd := "echo " + utils.ShellQuote("[dry-run] Vai executar: "+cmd)
963
964 if block.Language == "shell" {
965 out, err := a.executor.CaptureOutput(ctx, shell, []string{"-c", simCmd})
966 fmt.Println(string(out))
967 if err != nil {
968 fmt.Printf("❗ %s: %v\n", i18n.T("agent.dryrun.failed"), err)
969 }
970 } else if block.Language == "kubernetes" && strings.Contains(cmd, "apply") {
971 cmdDry := cmd + " --dry-run=client"
972 out, err := a.executor.CaptureOutput(ctx, shell, []string{"-c", cmdDry})
973 fmt.Println(string(out))
974 if err != nil {
975 fmt.Printf("❗ %s: %v\n", i18n.T("agent.dryrun.failed"), err)
976 }
977 } else {
978 out, _ := a.executor.CaptureOutput(ctx, shell, []string{"-c", "echo " + utils.ShellQuote("[dry-run] "+cmd)})
979 fmt.Println(string(out))
980 }
981 }
982 fmt.Println("---------------------------------------")
983}
984
985// editCommandBlock abre comandos em editor
986func (a *AgentMode) editCommandBlock(block agent.CommandBlock) ([]string, error) {

Callers 1

Calls 3

TFunction · 0.92
ShellQuoteFunction · 0.92
CaptureOutputMethod · 0.80

Tested by

no test coverage detected