Skip to content

Commit

Permalink
examples: improve hyprctl example
Browse files Browse the repository at this point in the history
  • Loading branch information
thiagokokada committed Jul 23, 2024
1 parent a28624e commit 70651dc
Showing 1 changed file with 43 additions and 27 deletions.
70 changes: 43 additions & 27 deletions examples/hyprctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,36 +51,52 @@ func main() {

flag.Parse()

m := map[string]func(){
"activewindow": func() {
v := must1(c.ActiveWindow())
fmt.Printf("%s\n", mustMarshalIndent(v))
},
"activeworkspace": func() {
v := must1(c.ActiveWorkspace())
fmt.Printf("%s\n", mustMarshalIndent(v))
},
"dispatch": func() {
dispatchFS.Parse(os.Args[2:])
v := must1(c.Dispatch(dispatch...))
fmt.Printf("%s\n", v)
},
"kill": func() {
v := must1(c.Kill())
fmt.Printf("%s\n", v)
},
"reload": func() {
v := must1(c.Reload())
fmt.Printf("%s\n", v)
},
"setcursor": func() {
setcursorFS.Parse(os.Args[2:])
v := must1(c.SetCursor(*theme, *size))
fmt.Printf("%s\n", v)
},
"version": func() {
v := must1(c.Version())
fmt.Printf("%s\n", mustMarshalIndent(v))
},
}

if len(os.Args) < 2 {
fmt.Println("Expected subcommand.")
fmt.Println("Expected one of the following subcommands:")
for k := range m {
fmt.Printf("- %s\n", k)
}
os.Exit(1)
}

switch os.Args[1] {
case "activewindow":
v := must1(c.ActiveWindow())
fmt.Printf("%s\n", mustMarshalIndent(v))
case "activeworkspace":
v := must1(c.ActiveWorkspace())
fmt.Printf("%s\n", mustMarshalIndent(v))
case "dispatch":
dispatchFS.Parse(os.Args[2:])
v := must1(c.Dispatch(dispatch...))
fmt.Printf("%s\n", v)
case "kill":
v := must1(c.Kill())
fmt.Printf("%s\n", v)
case "reload":
v := must1(c.Reload())
fmt.Printf("%s\n", v)
case "setcursor":
setcursorFS.Parse(os.Args[2:])
v := must1(c.SetCursor(*theme, *size))
fmt.Printf("%s\n", v)
case "version":
v := must1(c.Version())
fmt.Printf("%s\n", mustMarshalIndent(v))
default:
fmt.Printf("[ERROR] Unknown command: %s\n", os.Args[1])
subcmd := os.Args[1]
if fn, ok := m[subcmd]; ok {
fn()
} else {
fmt.Printf("Unknown subcommand: %s\n", subcmd)
os.Exit(1)
}
}

0 comments on commit 70651dc

Please sign in to comment.