Skip to content

Commit 83cfeb6

Browse files
nightcitybladenightcitybladey3owk1n
authored
fix(cli): open docs on Linux (#1467)
Co-authored-by: nightcityblade <nightcityblade@gmail.com> Co-authored-by: Kyle Wong <62775956+y3owk1n@users.noreply.github.com> Signed-off-by: Kyle Wong <62775956+y3owk1n@users.noreply.github.com>
1 parent 54782e3 commit 83cfeb6

7 files changed

Lines changed: 52 additions & 18 deletions

File tree

docs/CLI.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -99,7 +99,7 @@ Accepted by every command.
9999
| [`toggle-screen-share`](#neru-toggle-screen-share) | Hide overlays while sharing | Yes | macOS |
100100
| [`roles`](#neru-roles) | List the role vocabulary | No | All |
101101
| [`services`](#neru-services) | Manage the system service | No | macOS · Linux |
102-
| [`docs`](#neru-docs) | Open documentation in a browser | No | macOS |
102+
| [`docs`](#neru-docs) | Open documentation in a browser | No | macOS · Linux |
103103

104104
¹ Element discovery quality differs by platform: a full accessibility tree on
105105
macOS, an AT-SPI walk on Linux whose coverage depends on the application, and an
@@ -1546,7 +1546,7 @@ Open documentation in a browser.
15461546
neru docs config|cli
15471547
```
15481548
1549-
**Platforms:** macOS only; other platforms return `ERR_NOT_SUPPORTED`.
1549+
**Platforms:** macOS and Linux; other platforms return `ERR_NOT_SUPPORTED`.
15501550
15511551
URLs point at the Git tag matching the installed version. Development builds
15521552
fall back to `main`.

docs/CROSS_PLATFORM.md

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -894,9 +894,7 @@ command — that means less here than it does on macOS, whether or not the
894894

895895
**Linux**
896896

897-
1. `neru docs` — returns `CodeNotSupported` although the tray already opens
898-
URLs through `xdg-open` in the same repo
899-
2. Screen capture on KDE — X11 (`XGetImage`) and the wlroots family
897+
1. Screen capture on KDE — X11 (`XGetImage`) and the wlroots family
900898
(`wlr-screencopy-unstable-v1`) capture real pixels and honor a region, so
901899
the blessed stack is done. KWin implements no screencopy protocol Neru can
902900
use and reports `CodeNotSupported` naming itself. Its only pixel source is
Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,14 @@
1+
//go:build linux
2+
3+
package systray
4+
5+
import (
6+
"context"
7+
"os/exec"
8+
)
9+
10+
// Opens a URL or file path with the Linux desktop's default handler.
11+
// Does not validate the target or wait for the launched app.
12+
func openExternal(ctx context.Context, target string) error {
13+
return exec.CommandContext(ctx, "xdg-open", target).Start()
14+
}
Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,13 @@
1-
//go:build !darwin && !windows
1+
//go:build !darwin && !linux && !windows
22

33
package systray
44

55
import (
66
"context"
7-
"os/exec"
7+
8+
"github.com/y3owk1n/neru/internal/derrors"
89
)
910

10-
// Opens a URL or file path with xdg-open (Linux and other XDG desktops).
11-
// Does not validate the target or wait for the launched app.
12-
func openExternal(ctx context.Context, target string) error {
13-
return exec.CommandContext(ctx, "xdg-open", target).Run()
11+
func openExternal(_ context.Context, _ string) error {
12+
return derrors.New(derrors.CodeNotSupported, "opening external targets is not supported")
1413
}

internal/cli/docs.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ import (
66

77
// DocsCmd is the CLI docs command for opening Neru documentation in the browser.
88
//
9-
// macOS: uses open.
10-
// Other platforms: stubbed and returns CodeNotSupported until implemented.
9+
// macOS: uses open. Linux: uses xdg-open.
10+
// Other platforms return CodeNotSupported.
1111
var DocsCmd = &cobra.Command{
1212
Use: "docs",
1313
Short: "Open documentation in the browser",

internal/cli/docs_linux.go

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//go:build linux
2+
3+
package cli
4+
5+
import (
6+
"context"
7+
"os/exec"
8+
9+
"github.com/y3owk1n/neru/internal/buildinfo"
10+
"github.com/y3owk1n/neru/internal/derrors"
11+
)
12+
13+
func openDocsPage(path string) error {
14+
url := buildinfo.DocsURL(path, buildinfo.Version)
15+
16+
err := exec.CommandContext(context.Background(), "xdg-open", url).Start()
17+
if err != nil {
18+
return derrors.Wrap(err, derrors.CodeExecFailed, "failed to open documentation in browser")
19+
}
20+
21+
return nil
22+
}

internal/cli/docs_other.go

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,12 @@
1-
//go:build !darwin
1+
//go:build !darwin && !linux
22

33
package cli
44

5-
import (
6-
"github.com/y3owk1n/neru/internal/derrors"
7-
)
5+
import "github.com/y3owk1n/neru/internal/derrors"
86

97
func openDocsPage(path string) error {
10-
return derrors.New(derrors.CodeNotSupported, "open documentation is only implemented for macOS")
8+
return derrors.New(
9+
derrors.CodeNotSupported,
10+
"open documentation is only implemented for macOS and Linux",
11+
)
1112
}

0 commit comments

Comments
 (0)