grim/convey

Port from logrus to log/slog
default tip
5 months ago, Elliott Sales de Andrade
c588f9b3f559
Port from logrus to log/slog

This doesn't really take much advantage of structured logging beyond what is already done (`id` and `idColor`), and consequently the log handler does not try to do any handling of anything more than that (i.e., grouping, or arbitrary attributes beyond those defined).

One should maybe have a `Context` available to pass in, but there isn't one, and anyway, the log handler doesn't use it, so I've passed in a `TODO` instead.

Everything else is just normal import/rename changes.

Testing Done:
Ran `go run . run`

Reviewed at https://reviews.imfreedom.org/r/2871/
package script
import (
"fmt"
"os"
"os/exec"
"os/user"
"runtime"
"strings"
)
func windowsInterpreter() (string, error) {
intrepreter := os.Getenv("COMSPEC")
if intrepreter == "" {
intrepreter = "cmd.exe"
}
return intrepreter, nil
}
func darwinInterpreter() (string, error) {
user, err := user.Current()
if err != nil {
return "", err
}
path := "Local/Default/User/" + user.Username
args := []string{"localhost", "-read", path, "UserShell"}
buffer, err := exec.Command("dscl", args...).Output()
if err != nil {
return "", err
}
output := strings.TrimSpace(string(buffer))
parts := strings.Split(output, " ")
if len(parts) != 2 {
return "", fmt.Errorf("unexpected output from dscl: %q", output)
}
return strings.TrimSpace(parts[1]), nil
}
func posixInterpreter() (string, error) {
user, err := user.Current()
if err != nil {
return "", err
}
buffer, err := exec.Command("getent", "passwd", user.Uid).Output()
if err != nil {
return "", err
}
output := strings.TrimSpace(string(buffer))
fields := strings.Split(output, ":")
if len(fields) < 6 {
return "", fmt.Errorf("unexpected output from getent: %q", output)
}
intrepreter := fields[6]
if intrepreter == "" {
return "", fmt.Errorf("no shell found for user %q", user.Uid)
}
return intrepreter, nil
}
func findInterpreter(given string) (string, error) {
if given != "" {
return given, nil
}
if runtime.GOOS == "windows" {
return windowsInterpreter()
} else if runtime.GOOS == "darwin" {
return darwinInterpreter()
} else {
return posixInterpreter()
}
}