Files
LazyPM/pkg/repl/executor.go
Robin Olsen aabce0b0b2 refactor to use app package instead of service
refactor app to be composable
2026-02-28 23:30:31 +01:00

50 lines
926 B
Go

package repl
import (
"os/exec"
"strings"
"github.com/LazyBachelor/LazyPM/internal/commands/issues"
)
// execute processes the input command and returns the output
func execute(input string) (string, error) {
if input == "" {
return "", nil
}
if input == "help" {
return ReplHelp, nil
}
if input == "title" {
return ReplTitle, nil
}
if after, ok := strings.CutPrefix(input, "pm"); ok {
return executePMCommand(after)
}
return executeShellCommand(input)
}
func executeShellCommand(input string) (string, error) {
parts := strings.Fields(input)
if len(parts) == 0 {
return "", nil
}
cmd := exec.Command(parts[0], parts[1:]...)
output, err := cmd.CombinedOutput()
return string(output), err
}
func executePMCommand(input string) (string, error) {
parts := strings.Fields(input)
if len(parts) == 0 {
return "", nil
}
output, err := issues.ExecuteArgsString(parts)
return output, err
}