-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathexecutor.go
More file actions
38 lines (33 loc) · 762 Bytes
/
Copy pathexecutor.go
File metadata and controls
38 lines (33 loc) · 762 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
package main
import (
"errors"
"fmt"
"os"
"os/exec"
"strings"
)
// ExecuteSingle runs a command that does not involve pipes
func ExecuteSingle(args []string) {
StartTiming()
cmd := exec.Command(args[0], args[1:]...)
cmd.Stdin = os.Stdin
cmd.Stdout = os.Stdout
cmd.Stderr = os.Stderr
err := cmd.Run()
elapsed := EndTiming()
if err != nil {
if errors.Is(err, exec.ErrNotFound) {
fmt.Printf("myshell: command not found: %s\n", args[0])
// Fallback to Groq AI if available, otherwise local suggestions
if os.Getenv("GROQ_API_KEY") != "" {
HandleAICommand(strings.Join(args, " "))
} else {
SuggestCommand(args[0])
}
} else {
fmt.Fprintf(os.Stderr, "myshell: %v\n", err)
}
} else {
PrintExecutionTime(elapsed)
}
}