MCPcopy Index your code
hub / github.com/celer-pkg/celer / doExecute

Method doExecute

pkgs/cmd/exec_linux.go:18–69  ·  view source on GitHub ↗

doExecute implements Unix/Linux/macOS specific command execution. It handles direct command execution with optional shell wrapping.

(output io.Writer)

Source from the content-addressed store, hash-verified

16// doExecute implements Unix/Linux/macOS specific command execution.
17// It handles direct command execution with optional shell wrapping.
18func (e *executor) doExecute(output io.Writer) error {
19 var (
20 cmd *exec.Cmd
21 displayCmd string
22 )
23
24 // Build command and display string.
25 if len(e.args) == 0 {
26 cmd = exec.Command("bash", "-c", e.command)
27 displayCmd = e.command
28 } else {
29 cmd = exec.Command(e.command, e.args...)
30 displayCmd = e.command + " " + strings.Join(e.args, " ")
31 }
32
33 // Display execution info.
34 if e.title != "" {
35 color.Printf(color.Title, "\n%s\n", e.title)
36 color.Printf(color.Hint, "▶ %s\n", displayCmd)
37 }
38
39 // Verify and set working directory.
40 if e.workDir != "" {
41 if !fileio.PathExists(e.workDir) {
42 return fmt.Errorf("work directory does not exist: %s", e.workDir)
43 }
44 cmd.Dir = e.workDir
45 }
46
47 // Set up environment and stdin.
48 cmd.Env = os.Environ()
49 cmd.Stdin = os.Stdin
50
51 // Create and configure log file.
52 logFile, err := e.createLogFile(cmd)
53 if err != nil {
54 return fmt.Errorf("failed to setup logging: %w", err)
55 }
56 if logFile != nil {
57 defer logFile.Close()
58 }
59
60 // Route output to appropriate destinations.
61 e.configureOutputs(cmd, logFile, output)
62
63 // Execute command and return result.
64 if err := cmd.Run(); err != nil {
65 return fmt.Errorf("faild to execute command: %w", err)
66 }
67
68 return nil
69}

Callers 1

executeWithRetryMethod · 0.95

Calls 5

createLogFileMethod · 0.95
configureOutputsMethod · 0.95
PrintfFunction · 0.92
PathExistsFunction · 0.92
CommandMethod · 0.65

Tested by

no test coverage detected