feat: use exec.LookPath to find formatter executable
Signed-off-by: Brian McGee <brian@bmcgee.ie>
This commit is contained in:
parent
26c2ae1cda
commit
d8d666a132
|
@ -27,6 +27,7 @@ type Formatter struct {
|
||||||
|
|
||||||
name string
|
name string
|
||||||
log *log.Logger
|
log *log.Logger
|
||||||
|
executable string // path to the executable described by Command
|
||||||
|
|
||||||
// internal compiled versions of Includes and Excludes.
|
// internal compiled versions of Includes and Excludes.
|
||||||
includes []glob.Glob
|
includes []glob.Glob
|
||||||
|
@ -41,14 +42,24 @@ type Formatter struct {
|
||||||
batchSize int
|
batchSize int
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// Executable returns the path to the executable defined by Command
|
||||||
|
func (f *Formatter) Executable() string {
|
||||||
|
return f.executable
|
||||||
|
}
|
||||||
|
|
||||||
|
// Init is used to initialise internal state before this Formatter is ready to accept paths.
|
||||||
func (f *Formatter) Init(name string) error {
|
func (f *Formatter) Init(name string) error {
|
||||||
// capture the name from the config file
|
// capture the name from the config file
|
||||||
f.name = name
|
f.name = name
|
||||||
|
|
||||||
// test if the formatter is available
|
// test if the formatter is available
|
||||||
if err := exec.Command(f.Command, "--help").Run(); err != nil {
|
executable, err := exec.LookPath(f.Command)
|
||||||
|
if errors.Is(err, exec.ErrNotFound) {
|
||||||
return ErrFormatterNotFound
|
return ErrFormatterNotFound
|
||||||
|
} else if err != nil {
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
f.executable = executable
|
||||||
|
|
||||||
// initialise internal state
|
// initialise internal state
|
||||||
f.log = log.WithPrefix("format | " + name)
|
f.log = log.WithPrefix("format | " + name)
|
||||||
|
|
Reference in New Issue
Block a user