Skip to content

Commit

Permalink
also write command debug line to stderr
Browse files Browse the repository at this point in the history
  • Loading branch information
phm07 committed Jul 3, 2024
1 parent 382a59c commit 38124c7
Showing 1 changed file with 14 additions and 11 deletions.
25 changes: 14 additions & 11 deletions internal/state/state.go
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ package state
import (
"context"
"fmt"
"io"
"os"
"strings"

Expand Down Expand Up @@ -87,25 +88,27 @@ func (c *state) newClient() (hcapi2.Client, error) {
return nil, err
}

var debugWriter io.Writer
if filePath == "" {
opts = append(opts, hcloud.WithDebugWriter(os.Stderr))
debugWriter = os.Stderr
} else {
f, err := os.OpenFile(filePath, os.O_CREATE|os.O_APPEND|os.O_WRONLY, 0644)
if err != nil {
return nil, err
}
debugWriter = f
}

quotedArgs := make([]string, 0, len(os.Args))
for _, arg := range os.Args {
quotedArgs = append(quotedArgs, fmt.Sprintf("%q", arg))
}
_, err = f.WriteString("--- Command:\n" + strings.Join(quotedArgs, " ") + "\n\n\n\n")
if err != nil {
return nil, err
}

opts = append(opts, hcloud.WithDebugWriter(f))
quotedArgs := make([]string, 0, len(os.Args))
for _, arg := range os.Args {
quotedArgs = append(quotedArgs, fmt.Sprintf("%q", arg))
}
_, err = debugWriter.Write([]byte("--- Command:\n" + strings.Join(quotedArgs, " ") + "\n\n\n\n"))
if err != nil {
return nil, err
}

opts = append(opts, hcloud.WithDebugWriter(debugWriter))
}

pollInterval, err := config.OptionPollInterval.Get(c.config)
Expand Down

0 comments on commit 38124c7

Please sign in to comment.