Refactor bee CLI and LiveCD integration
This commit is contained in:
29
audit/internal/platform/tools.go
Normal file
29
audit/internal/platform/tools.go
Normal file
@@ -0,0 +1,29 @@
|
||||
package platform
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"os"
|
||||
"os/exec"
|
||||
"strings"
|
||||
)
|
||||
|
||||
func (s *System) TailFile(path string, lines int) string {
|
||||
raw, err := os.ReadFile(path)
|
||||
if err != nil {
|
||||
return fmt.Sprintf("read %s: %v", path, err)
|
||||
}
|
||||
all := strings.Split(strings.TrimRight(string(raw), "\n"), "\n")
|
||||
if lines <= 0 || len(all) <= lines {
|
||||
return string(raw)
|
||||
}
|
||||
return strings.Join(all[len(all)-lines:], "\n")
|
||||
}
|
||||
|
||||
func (s *System) CheckTools(names []string) []ToolStatus {
|
||||
out := make([]ToolStatus, 0, len(names))
|
||||
for _, name := range names {
|
||||
path, err := exec.LookPath(name)
|
||||
out = append(out, ToolStatus{Name: name, Path: path, OK: err == nil})
|
||||
}
|
||||
return out
|
||||
}
|
||||
Reference in New Issue
Block a user