@@ -2,10 +2,12 @@ package main
2
2
3
3
import (
4
4
"context"
5
- "log "
5
+ "fmt "
6
6
"os"
7
7
"os/signal"
8
+ "regexp"
8
9
"runtime"
10
+ "strings"
9
11
"time"
10
12
11
13
_ "github.com/joho/godotenv/autoload"
@@ -57,7 +59,7 @@ this repository has new commits, Pico will automatically reconfigure.`,
57
59
Action : func (c * cli.Context ) (err error ) {
58
60
if ! c .Args ().Present () {
59
61
cli .ShowCommandHelp (c , "run" )
60
- return errors .New ("missing argument: target " )
62
+ return errors .New ("missing argument: configuration repository URL " )
61
63
}
62
64
63
65
ctx , cancel := context .WithCancel (context .Background ())
@@ -72,9 +74,7 @@ this repository has new commits, Pico will automatically reconfigure.`,
72
74
}
73
75
}
74
76
75
- zap .L ().Debug ("initialising service" )
76
-
77
- svc , err := service .Initialise (service.Config {
77
+ cfg := service.Config {
78
78
Target : task.Repo {
79
79
URL : c .Args ().First (),
80
80
User : c .String ("git-username" ),
@@ -90,7 +90,11 @@ this repository has new commits, Pico will automatically reconfigure.`,
90
90
VaultPath : c .String ("vault-path" ),
91
91
VaultRenewal : c .Duration ("vault-renew-interval" ),
92
92
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 )
94
98
if err != nil {
95
99
return errors .Wrap (err , "failed to initialise" )
96
100
}
@@ -111,26 +115,32 @@ this repository has new commits, Pico will automatically reconfigure.`,
111
115
case err = <- errs :
112
116
}
113
117
118
+ if strings .ToLower (os .Getenv ("LOG_LEVEL" )) == "debug" {
119
+ doTrace ()
120
+ }
121
+
114
122
return
115
123
},
116
124
},
117
125
}
118
126
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
-
132
127
err := app .Run (os .Args )
133
128
if err != nil {
134
129
zap .L ().Fatal ("exit" , zap .Error (err ))
135
130
}
136
131
}
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