Skip to content

Commit d8d666a

Browse files
committed
feat: use exec.LookPath to find formatter executable
Signed-off-by: Brian McGee <[email protected]>
1 parent 26c2ae1 commit d8d666a

File tree

1 file changed

+14
-3
lines changed

1 file changed

+14
-3
lines changed

internal/format/format.go

+14-3
Original file line numberDiff line numberDiff line change
@@ -25,8 +25,9 @@ type Formatter struct {
2525
// Excludes is an optional list of glob patterns used to exclude certain files from this Formatter.
2626
Excludes []string
2727

28-
name string
29-
log *log.Logger
28+
name string
29+
log *log.Logger
30+
executable string // path to the executable described by Command
3031

3132
// internal compiled versions of Includes and Excludes.
3233
includes []glob.Glob
@@ -41,14 +42,24 @@ type Formatter struct {
4142
batchSize int
4243
}
4344

45+
// Executable returns the path to the executable defined by Command
46+
func (f *Formatter) Executable() string {
47+
return f.executable
48+
}
49+
50+
// Init is used to initialise internal state before this Formatter is ready to accept paths.
4451
func (f *Formatter) Init(name string) error {
4552
// capture the name from the config file
4653
f.name = name
4754

4855
// test if the formatter is available
49-
if err := exec.Command(f.Command, "--help").Run(); err != nil {
56+
executable, err := exec.LookPath(f.Command)
57+
if errors.Is(err, exec.ErrNotFound) {
5058
return ErrFormatterNotFound
59+
} else if err != nil {
60+
return err
5161
}
62+
f.executable = executable
5263

5364
// initialise internal state
5465
f.log = log.WithPrefix("format | " + name)

0 commit comments

Comments
 (0)