@@ -2,22 +2,42 @@ package controller
22
33import (
44 "context"
5+ "os"
56
67 "github.com/evilmartians/lefthook/v2/internal/config"
8+ "github.com/evilmartians/lefthook/v2/internal/log"
9+ "github.com/evilmartians/lefthook/v2/internal/run/controller/command/replacer"
710 "github.com/evilmartians/lefthook/v2/internal/run/controller/exec"
11+ "github.com/evilmartians/lefthook/v2/internal/system"
812)
913
10- func (c * Controller ) setup (ctx context.Context , setupInstructions []* config.SetupInstruction ) error {
14+ func (c * Controller ) setup (
15+ ctx context.Context ,
16+ opts Options ,
17+ setupInstructions []* config.SetupInstruction ,
18+ ) error {
1119 if len (setupInstructions ) == 0 {
1220 return nil
1321 }
1422
23+ log .StopSpinner ()
24+ defer log .StartSpinner ()
25+
26+ replacer := replacer .New (c .git , "" , "" ).
27+ AddTemplates (opts .Templates ).
28+ AddGitArgs (opts .GitArgs )
29+
1530 commands := make ([]string , 0 , len (setupInstructions ))
1631 for _ , instr := range setupInstructions {
17- commands = append (commands , instr .Run )
32+ if err := replacer .Discover (instr .Run , nil ); err != nil {
33+ return err
34+ }
35+
36+ rawCommands , _ := replacer .ReplaceAndSplit (instr .Run , system .MaxCmdLen ())
37+ commands = append (commands , rawCommands ... )
1838 }
1939
20- return c . run ( ctx , "setup" , true , exec. Options {
21- Commands : commands ,
22- } )
40+ log . LogSetup ()
41+
42+ return c . executor . Execute ( ctx , exec. Options { Commands : commands }, system . NullReader , os . Stdout )
2343}
0 commit comments