File tree 1 file changed +14
-3
lines changed
1 file changed +14
-3
lines changed Original file line number Diff line number Diff line change @@ -25,8 +25,9 @@ type Formatter struct {
25
25
// Excludes is an optional list of glob patterns used to exclude certain files from this Formatter.
26
26
Excludes []string
27
27
28
- name string
29
- log * log.Logger
28
+ name string
29
+ log * log.Logger
30
+ executable string // path to the executable described by Command
30
31
31
32
// internal compiled versions of Includes and Excludes.
32
33
includes []glob.Glob
@@ -41,14 +42,24 @@ type Formatter struct {
41
42
batchSize int
42
43
}
43
44
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.
44
51
func (f * Formatter ) Init (name string ) error {
45
52
// capture the name from the config file
46
53
f .name = name
47
54
48
55
// 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 ) {
50
58
return ErrFormatterNotFound
59
+ } else if err != nil {
60
+ return err
51
61
}
62
+ f .executable = executable
52
63
53
64
// initialise internal state
54
65
f .log = log .WithPrefix ("format | " + name )
You can’t perform that action at this time.
0 commit comments