Deployment and lifecycle management for Nix
0
fork

Configure Feed

Select the types of activity you want to include in your feed.

cli: clean up command pipes

+13 -72
cli

This is a binary file and will not be displayed.

+7 -22
cmd/cli/builder/main.go
··· 6 6 "encoding/json" 7 7 "errors" 8 8 "fmt" 9 - "io" 10 9 "log/slog" 11 10 "net/url" 12 11 "os" ··· 47 46 outputStr := strings.Join(outputs, "\n") 48 47 49 48 pushCmd := exec.Command("attic", "push", "--stdin", "--ignore-upstream-cache-filter", "--jobs", a.Jobs, a.Cache) 50 - stdout, err := pushCmd.StdoutPipe() 51 - if err != nil { 52 - return fmt.Errorf("error creating stdout: %v", err) 53 - } 54 - stderr, err := pushCmd.StderrPipe() 49 + 50 + // Directly attach streams for real-time output 51 + pushCmd.Stdout = os.Stdout 52 + pushCmd.Stderr = os.Stderr 53 + 54 + stdin, err := pushCmd.StdinPipe() 55 55 if err != nil { 56 - return fmt.Errorf("error creating stderr: %v", err) 56 + return fmt.Errorf("error creating stdin: %v", err) 57 57 } 58 - stdin, _ := pushCmd.StdinPipe() 59 58 60 59 err = pushCmd.Start() 61 60 if err != nil { 62 61 return fmt.Errorf("failed to start command: %v", err) 63 62 } 64 - 65 - var ioErr error 66 - go func() { 67 - _, ioErr = io.Copy(os.Stdout, stdout) 68 - if ioErr != nil { 69 - slog.Error("failed to configure stdout") 70 - } 71 - }() 72 - go func() { 73 - _, ioErr = io.Copy(os.Stderr, stderr) 74 - if ioErr != nil { 75 - slog.Error("failed to configure stderr") 76 - } 77 - }() 78 63 79 64 _, err = stdin.Write([]byte(outputStr)) 80 65 if err != nil {
+6 -50
cmd/cli/commands/main.go
··· 2 2 3 3 import ( 4 4 "fmt" 5 - "io" 6 5 "log/slog" 7 6 "os" 8 7 "os/exec" ··· 10 9 ) 11 10 12 11 func SimpleRun(cmd *exec.Cmd) error { 13 - // Set up the pipes for stdout and stderr 14 - stdout, err := cmd.StdoutPipe() 15 - if err != nil { 16 - return fmt.Errorf("error creating stdout: %v", err) 17 - } 18 - stderr, err := cmd.StderrPipe() 19 - if err != nil { 20 - return fmt.Errorf("error creating stderr: %v", err) 21 - } 12 + // Directly attach streams for real-time output 13 + cmd.Stdout = os.Stdout 14 + cmd.Stderr = os.Stderr 22 15 23 16 slog.Debug("Running command", "cmd", cmd.String()) 24 - err = cmd.Start() 25 - if err != nil { 26 - return fmt.Errorf("error starting command: %v", err) 27 - } 28 17 29 - var ioErr error 30 - go func() { 31 - _, ioErr = io.Copy(os.Stdout, stdout) // Redirect stdout to terminal's stdout 32 - if ioErr != nil { 33 - slog.Error("failed to configure stdout") 34 - } 35 - }() 36 - go func() { 37 - _, ioErr = io.Copy(os.Stderr, stderr) // Redirect stderr to terminal's stderr 38 - if ioErr != nil { 39 - slog.Error("failed to configure stderr") 40 - } 41 - }() 42 - 43 - err = cmd.Wait() 18 + err := cmd.Run() 44 19 if err != nil { 45 20 return fmt.Errorf("failed to run command: %v", err) 46 21 } 47 22 48 - if ioErr != nil { 49 - return fmt.Errorf("error copying output: %v", ioErr) 50 - } 51 - 52 23 return nil 53 24 } 54 25 55 26 func Run(cmd *exec.Cmd) (string, error) { 56 - // Set up the pipes for stderr 57 - stderr, err := cmd.StderrPipe() 58 - if err != nil { 59 - return "", fmt.Errorf("error creating stderr: %v", err) 60 - } 27 + // Attach stderr for real-time error output 28 + cmd.Stderr = os.Stderr 61 29 62 30 slog.Debug("Running command", "cmd", cmd.String()) 63 31 64 - var ioErr error 65 - go func() { 66 - _, ioErr = io.Copy(os.Stderr, stderr) // Redirect stderr to terminal's stderr 67 - if ioErr != nil { 68 - slog.Error("failed to configure stderr") 69 - } 70 - }() 71 - 72 32 stdout, err := cmd.Output() 73 33 if err != nil { 74 34 return "", fmt.Errorf("failed to run command: %v", err) 75 - } 76 - 77 - if ioErr != nil { 78 - return "", fmt.Errorf("error copying output: %v", ioErr) 79 35 } 80 36 81 37 return strings.TrimSpace(string(stdout)), nil