@@ -2,10 +2,12 @@ package main
22
33import (
44 "context"
5- "log "
5+ "fmt "
66 "os"
77 "os/signal"
8+ "regexp"
89 "runtime"
10+ "strings"
911 "time"
1012
1113 _ "github.com/joho/godotenv/autoload"
@@ -57,7 +59,7 @@ this repository has new commits, Pico will automatically reconfigure.`,
5759 Action : func (c * cli.Context ) (err error ) {
5860 if ! c .Args ().Present () {
5961 cli .ShowCommandHelp (c , "run" )
60- return errors .New ("missing argument: target " )
62+ return errors .New ("missing argument: configuration repository URL " )
6163 }
6264
6365 ctx , cancel := context .WithCancel (context .Background ())
@@ -72,9 +74,7 @@ this repository has new commits, Pico will automatically reconfigure.`,
7274 }
7375 }
7476
75- zap .L ().Debug ("initialising service" )
76-
77- svc , err := service .Initialise (service.Config {
77+ cfg := service.Config {
7878 Target : task.Repo {
7979 URL : c .Args ().First (),
8080 User : c .String ("git-username" ),
@@ -90,7 +90,11 @@ this repository has new commits, Pico will automatically reconfigure.`,
9090 VaultPath : c .String ("vault-path" ),
9191 VaultRenewal : c .Duration ("vault-renew-interval" ),
9292 VaultConfig : c .String ("vault-config-path" ),
93- })
93+ }
94+
95+ zap .L ().Debug ("initialising service" , zap .Any ("config" , cfg ))
96+
97+ svc , err := service .Initialise (cfg )
9498 if err != nil {
9599 return errors .Wrap (err , "failed to initialise" )
96100 }
@@ -111,26 +115,32 @@ this repository has new commits, Pico will automatically reconfigure.`,
111115 case err = <- errs :
112116 }
113117
118+ if strings .ToLower (os .Getenv ("LOG_LEVEL" )) == "debug" {
119+ doTrace ()
120+ }
121+
114122 return
115123 },
116124 },
117125 }
118126
119- if os .Getenv ("DEBUG" ) != "" {
120- go func () {
121- sigs := make (chan os.Signal , 1 )
122- signal .Notify (sigs , os .Interrupt )
123- buf := make ([]byte , 1 << 20 )
124- for {
125- <- sigs
126- stacklen := runtime .Stack (buf , true )
127- log .Printf ("\n Printing goroutine stack trace because `DEBUG` was set.\n %s\n " , buf [:stacklen ])
128- }
129- }()
130- }
131-
132127 err := app .Run (os .Args )
133128 if err != nil {
134129 zap .L ().Fatal ("exit" , zap .Error (err ))
135130 }
136131}
132+
133+ var waitpoints = regexp .MustCompile (`__waitpoint__(.+)\(` )
134+
135+ func doTrace () {
136+ buf := make ([]byte , 1 << 20 )
137+ stacklen := runtime .Stack (buf , true )
138+
139+ fmt .Printf ("\n Printing goroutine stack trace because `DEBUG` was set.\n %s\n " , buf [:stacklen ])
140+ fmt .Println ("Code that was waiting:" )
141+
142+ for _ , s := range waitpoints .FindAllStringSubmatch (string (buf [:stacklen ]), 1 ) {
143+ fmt .Printf (" - %s\n " , s [1 ])
144+ }
145+ fmt .Println ("\n See the docs on https://pico.sh/ for more information." )
146+ }
0 commit comments