2023-08-15 18:41:11 +08:00
|
|
|
package runner
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
"strings"
|
|
|
|
"time"
|
|
|
|
)
|
|
|
|
|
|
|
|
// A Profile defines what to run when invoked on the target directory.
|
|
|
|
type Profile struct {
|
|
|
|
Name string // Name of the profile.
|
|
|
|
ID string // ID of the profile.
|
|
|
|
Commands []string // Commands to run on the profile.
|
|
|
|
Environ map[string]string // Environment variables
|
|
|
|
|
2023-08-15 21:42:18 +08:00
|
|
|
Output []string // List of globs to match output files, fed directly into the shell.
|
2023-08-15 18:41:11 +08:00
|
|
|
OutputDir string // The globs will be matched in this relative directory.
|
|
|
|
}
|
|
|
|
|
|
|
|
type LogEntry struct {
|
|
|
|
Time time.Time
|
|
|
|
Text string
|
|
|
|
OutFd int // 0(manual) 1(stdout) 2(stderr)
|
|
|
|
}
|
|
|
|
|
|
|
|
type Logs []LogEntry
|
|
|
|
|
|
|
|
func (logs Logs) String() string {
|
|
|
|
var buf strings.Builder
|
|
|
|
|
|
|
|
for _, log := range logs {
|
|
|
|
switch log.OutFd {
|
|
|
|
case 0:
|
|
|
|
fmt.Fprintf(&buf, "%s %s\n", log.Time.Format("15:04:05"), log.Text)
|
|
|
|
case 1, 2:
|
|
|
|
fmt.Fprintf(&buf, "%s %s\n", log.Time.Format("15:04:05"), log.Text)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
return buf.String()
|
|
|
|
}
|