Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Errcheck in examples #40

Merged
merged 2 commits into from
Sep 12, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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/[email protected] ./...

- name: Errcheck
run: go run github.com/kisielk/[email protected] -ignoretests ./ ./event
run: go run github.com/kisielk/[email protected] -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
Loading