42 lines
938 B
Go
42 lines
938 B
Go
|
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
|
||
|
|
||
|
Output []string // List of globs to match output files.
|
||
|
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()
|
||
|
}
|