Skip to content

Commit

Permalink
Merge pull request #40 from thiagokokada/errcheck-in-examples
Browse files Browse the repository at this point in the history
Errcheck in examples
  • Loading branch information
thiagokokada authored Sep 12, 2024
2 parents fbd5013 + 58a4efb commit 1521d4b
Show file tree
Hide file tree
Showing 4 changed files with 30 additions and 24 deletions.
2 changes: 1 addition & 1 deletion .github/workflows/go.yml
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ jobs:
run: go run honnef.co/go/tools/cmd/staticcheck@2023.1.7 ./...

- name: Errcheck
run: go run github.com/kisielk/errcheck@v1.7.0 -ignoretests ./ ./event
run: go run github.com/kisielk/errcheck@v1.7.0 -ignoretests ./...

- name: Build
run: go build -v ./...
Expand Down
12 changes: 9 additions & 3 deletions examples/events/events.go
Original file line number Diff line number Diff line change
Expand Up @@ -13,6 +13,12 @@ type ev struct {
event.DefaultEventHandler
}

func must(err error) {
if err != nil {
panic(err)
}
}

func (e *ev) Workspace(w event.WorkspaceName) {
fmt.Printf("Workspace: %+v\n", w)
}
Expand All @@ -29,15 +35,15 @@ func main() {
defer cancel()

c := event.MustClient()
defer c.Close()
defer must(c.Close())

// Will listen for events for 5 seconds and exit
c.Subscribe(
must(c.Subscribe(
ctx,
&ev{},
event.EventWorkspace,
event.EventActiveWindow,
)
))

fmt.Println("Bye!")
}
36 changes: 18 additions & 18 deletions examples/hyprctl/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -51,9 +51,9 @@ func mustMarshalIndent(v any) []byte {
}

func usage(m map[string]func(args []string)) {
fmt.Fprintf(out, "Usage of %s:\n", os.Args[0])
fmt.Fprintf(out, " %s [subcommand] <options>\n\n", os.Args[0])
fmt.Fprintf(out, "Available subcommands:\n")
must1(fmt.Fprintf(out, "Usage of %s:\n", os.Args[0]))
must1(fmt.Fprintf(out, " %s [subcommand] <options>\n\n", os.Args[0]))
must1(fmt.Fprintf(out, "Available subcommands:\n"))

// Sort keys before printing, since Go randomises order
subcommands := make([]string, len(m))
Expand All @@ -64,7 +64,7 @@ func usage(m map[string]func(args []string)) {
}
sort.Strings(subcommands)
for _, s := range subcommands {
fmt.Fprintf(out, " - %s\n", s)
must1(fmt.Fprintf(out, " - %s\n", s))
}
}

Expand All @@ -88,16 +88,16 @@ func main() {
m := map[string]func(args []string){
"activewindow": func(_ []string) {
v := must1(c.ActiveWindow())
fmt.Printf("%s\n", mustMarshalIndent(v))
must1(fmt.Printf("%s\n", mustMarshalIndent(v)))
},
"activeworkspace": func(_ []string) {
v := must1(c.ActiveWorkspace())
fmt.Printf("%s\n", mustMarshalIndent(v))
must1(fmt.Printf("%s\n", mustMarshalIndent(v)))
},
"batch": func(args []string) {
batchFS.Parse(args)
must(batchFS.Parse(args))
if len(batch) == 0 {
fmt.Fprintf(out, "Error: at least one '-c' is required for batch.\n")
must1(fmt.Fprintf(out, "Error: at least one '-c' is required for batch.\n"))
os.Exit(1)
} else {
// Batch commands are done in the following way:
Expand All @@ -106,35 +106,35 @@ func main() {
fmt.Sprintf("[[BATCH]]%s", strings.Join(batch, ";")),
)
v := must1(c.RawRequest(r))
fmt.Printf("%s\n", v)
must1(fmt.Printf("%s\n", v))
}
},
"dispatch": func(args []string) {
dispatchFS.Parse(args)
must(dispatchFS.Parse(args))
if len(dispatch) == 0 {
fmt.Fprintf(out, "Error: at least one '-c' is required for dispatch.\n")
must1(fmt.Fprintf(out, "Error: at least one '-c' is required for dispatch.\n"))
os.Exit(1)
} else {
v := must1(c.Dispatch(dispatch...))
fmt.Printf("%s\n", v)
must1(fmt.Printf("%s\n", v))
}
},
"kill": func(_ []string) {
v := must1(c.Kill())
fmt.Printf("%s\n", v)
must1(fmt.Printf("%s\n", v))
},
"reload": func(_ []string) {
v := must1(c.Reload())
fmt.Printf("%s\n", v)
must1(fmt.Printf("%s\n", v))
},
"setcursor": func(_ []string) {
setcursorFS.Parse(os.Args[2:])
must(setcursorFS.Parse(os.Args[2:]))
v := must1(c.SetCursor(*theme, *size))
fmt.Printf("%s\n", v)
must1(fmt.Printf("%s\n", v))
},
"version": func(_ []string) {
v := must1(c.Version())
fmt.Printf("%s\n", mustMarshalIndent(v))
must1(fmt.Printf("%s\n", mustMarshalIndent(v)))
},
}

Expand All @@ -151,7 +151,7 @@ func main() {
c = hyprland.MustClient()
run(os.Args[2:])
} else {
fmt.Fprintf(out, "Error: unknown subcommand: %s\n", subcommand)
must1(fmt.Fprintf(out, "Error: unknown subcommand: %s\n", subcommand))
os.Exit(1)
}
}
4 changes: 2 additions & 2 deletions examples/hyprtabs/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,12 +28,12 @@ func main() {

aWindow := must1(client.ActiveWindow())
if len(aWindow.Grouped) > 0 {
client.Dispatch(
must1(client.Dispatch(
// If we are already in a group, ungroup
"togglegroup",
// Make the current window as master (when using master layout)
"layoutmsg swapwithmaster master",
)
))
} else {
var cmdbuf []string
aWorkspace := must1(client.ActiveWorkspace())
Expand Down

0 comments on commit 1521d4b

Please sign in to comment.