-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathdefault_handler.go
More file actions
41 lines (37 loc) · 922 Bytes
/
default_handler.go
File metadata and controls
41 lines (37 loc) · 922 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
39
40
41
package main
import (
"fmt"
"strings"
)
// DefaultCommandHandler provides basic command functionality
type DefaultCommandHandler struct{}
func (h *DefaultCommandHandler) HandleCommand(cmd string, args []string) bool {
switch cmd {
case "help":
fmt.Println("Available commands:")
for cmd, desc := range h.GetHelp() {
fmt.Printf(" %-10s - %s\n", cmd, desc)
}
return true
case "exit":
fmt.Println("Exiting program...")
return false
case "echo":
fmt.Println(strings.Join(args, " "))
return true
case "info":
pid, _, _ := getCurrentProcessId.Call()
fmt.Printf("Process ID: %d\n", pid)
return true
default:
return true // Pass to next handler
}
}
func (h *DefaultCommandHandler) GetHelp() map[string]string {
return map[string]string{
"help": "Display available commands",
"exit": "Exit program",
"echo": "Display the provided text",
"info": "Display process information",
}
}