MCPcopy Create free account
hub / github.com/celer-pkg/celer / doExecute

Method doExecute

pkgs/cmd/exec_windows.go:19–67  ·  view source on GitHub ↗

doExecute implements Windows specific command execution. It handles both native Windows commands and MSYS2/bash environments.

(output io.Writer)

Source from the content-addressed store, hash-verified

17// doExecute implements Windows specific command execution.
18// It handles both native Windows commands and MSYS2/bash environments.
19func (e *executor) doExecute(output io.Writer) error {
20 var (
21 cmd *exec.Cmd
22 displayCmd string
23 )
24
25 // Build command and display string based on environment mode.
26 if e.msys2Env {
27 cmd = e.buildMSYS2Command(&displayCmd)
28 } else {
29 cmd = e.buildNativeCommand(&displayCmd)
30 }
31
32 // Display execution info.
33 if e.title != "" {
34 color.Printf(color.Title, "\n%s\n", e.title)
35 color.Printf(color.Hint, "▶ %s\n", displayCmd)
36 }
37
38 // Verify and set working directory.
39 if e.workDir != "" {
40 if !fileio.PathExists(e.workDir) {
41 return fmt.Errorf("work directory does not exist: %s", e.workDir)
42 }
43 cmd.Dir = e.workDir
44 }
45
46 // Set up stdin.
47 cmd.Stdin = os.Stdin
48
49 // Create and configure log file.
50 logFile, err := e.createLogFile(cmd)
51 if err != nil {
52 return fmt.Errorf("failed to setup logging: %w", err)
53 }
54 if logFile != nil {
55 defer logFile.Close()
56 }
57
58 // Route output to appropriate destinations.
59 e.configureOutputs(cmd, logFile, output)
60
61 // Execute command and return result.
62 if err := cmd.Run(); err != nil {
63 return fmt.Errorf("faild to execute command -> %w", err)
64 }
65
66 return nil
67}
68
69// buildMSYS2Command constructs a command to run in MSYS2/bash environment.
70func (e *executor) buildMSYS2Command(displayCmd *string) *exec.Cmd {

Callers

nothing calls this directly

Calls 6

buildMSYS2CommandMethod · 0.95
buildNativeCommandMethod · 0.95
createLogFileMethod · 0.95
configureOutputsMethod · 0.95
PrintfFunction · 0.92
PathExistsFunction · 0.92

Tested by

no test coverage detected