Documentation
¶
Overview ¶
Package clitool installs the gadak binary onto PATH. Unix uses a symlink; Windows copies (symlink creation needs Developer Mode or elevation, so the default path fails). Shared by `gadak install-cli` and the desktop "Install Command Line Tool…" menu so both surfaces use the same resolve / install / PATH-advice logic.
LookPathThen / ResolveNPM / RaycastExtDir live here too: the CLI install verb and the desktop catalog must try the same candidates.
Index ¶
- Constants
- Variables
- func DefaultDir(pathEnv string) (string, error)
- func DefaultDirFor(pathEnv, goos string) (string, error)
- func ExpandHome(p string) (string, error)
- func Install(p Plan, force bool) error
- func LookPathThen(name string, fallbacks []string, look func(string) (string, error), ...) (string, bool)
- func NPMNotFoundDetail() string
- func PathContains(pathEnv, dir string) bool
- func PathExportAdvise(dir, shell string) (line, rc string)
- func PathExportAdviseFor(dir, shell, goos string) (line, rc string)
- func RaycastExtDir() (string, error)
- func RecordedDesktopExe() string
- func ResolveDir(dirFlag, pathEnv string) (string, error)
- func ResolveNPM(look func(string) (string, error), present func(string) bool) (string, bool)
- func TildeHome(path string) string
- type Plan
Constants ¶
const ( StatusMissing = "missing" // nothing at Dest StatusLinked = "linked" // Dest is already the desired install (symlink or copy) StatusConflict = "conflict" // Dest exists but is not the desired install )
Destination status after Resolve.
const ( MethodSymlink = "symlink" MethodCopy = "copy" )
How Install places Dest. Windows copies: creating a symlink needs Developer Mode or elevation, so the default path fails. Unix keeps a symlink.
const RaycastExtDirName = "raycast-extension"
RaycastExtDirName is the directory under the gadak home that holds the unpacked Raycast extension. Profile is ignored: one copy per home.
Variables ¶
var DesktopExePathFile string
DesktopExePathFile is the pointer file written after a successful install-cli when gadak-desktop.exe sat next to the source binary. Empty means <UserConfigDir>/gadak/desktop-exe-path. Tests override to a temp path so they never touch the real UserConfigDir. Not GADAK_HOME: that directory is store-owned.
var NPMFallbackPaths = []string{
"/opt/homebrew/bin/npm",
"/usr/local/bin/npm",
}
NPMFallbackPaths is LookPath("npm") then these, first existing+executable wins. Same brew locations as contrib/raycast/src/gadak.ts GADAK_CANDIDATES, opposite direction (we are finding npm, not gadak).
Owned here so `gadak raycast install` and the desktop catalog cannot drift.
Functions ¶
func DefaultDir ¶
DefaultDir chooses an install directory when --dir is omitted.
func DefaultDirFor ¶ added in v0.17.0
DefaultDirFor is DefaultDir with an explicit GOOS so the Windows default can be tested on any host (same shape as installMethodFor).
Unix order:
- ~/.local/bin if it exists and is already on PATH
- /usr/local/bin if it is on PATH and writable without sudo
- ~/.local/bin otherwise (create on Install; caller may warn about PATH)
Windows: %LOCALAPPDATA%\Programs\gadak (empty LOCALAPPDATA → UserHomeDir + AppData\Local). Unix candidates are not considered.
func ExpandHome ¶
ExpandHome expands a leading ~ or ~/… using os.UserHomeDir. Other paths are returned cleaned as-is.
func Install ¶
Install creates Dir if needed and places Dest according to p.Method (symlink on Unix, copy on Windows). Empty Method is treated as symlink so a Plan built by older callers keeps the previous behaviour. When Status is linked, Install does not touch Dest (it may still record gadak-desktop.exe next to Source as a discovery fallback). When Status is conflict and force is false, Install returns an error without touching the filesystem. force replaces an existing Dest.
func LookPathThen ¶ added in v0.16.0
func LookPathThen(name string, fallbacks []string, look func(string) (string, error), present func(string) bool) (string, bool)
LookPathThen is LookPath(name), then the first fallback that present reports. look and present are injected so tests can assert order without touching the host. A nil present falls back to an execute-bit check (on Windows, any regular file).
func NPMNotFoundDetail ¶ added in v0.16.0
func NPMNotFoundDetail() string
NPMNotFoundDetail names every place ResolveNPM looks. Generated from NPMFallbackPaths so the wording cannot drift from the table.
func PathContains ¶
PathContains reports whether dir appears as a PATH entry (exact, after Clean). Empty entries are ignored. Leading ~ in pathEnv entries is expanded.
func PathExportAdvise ¶
PathExportAdvise returns a pasteable one-liner and a suggested shell rc path for persistence (rc may be empty). Unix shells only; Windows uses PathExportAdviseFor.
func PathExportAdviseFor ¶ added in v0.16.0
PathExportAdviseFor is PathExportAdvise with an explicit GOOS. Windows has no verified one-liner in this package (setx truncates PATH; this runner has not executed a Windows PATH edit), so the line only names the directory.
func RaycastExtDir ¶ added in v0.16.0
RaycastExtDir is $GADAK_HOME/raycast-extension (profile ignored). A DirFor error is returned: the install verb must not write to a guessed path. Catalog display that cannot fail should fall back at the call site.
func RecordedDesktopExe ¶ added in v0.17.0
func RecordedDesktopExe() string
RecordedDesktopExe returns the path stored in DesktopExePathFile when that path names an existing non-directory file. Missing or stale records are ignored (empty string).
func ResolveDir ¶
ResolveDir returns the absolute install directory. Empty flag → DefaultDir(pathEnv). Leading ~ is expanded.
func ResolveNPM ¶ added in v0.16.0
ResolveNPM is LookPath("npm"), then NPMFallbackPaths.
Types ¶
type Plan ¶
type Plan struct {
Source string
Dir string
Dest string
// Status is one of StatusMissing, StatusLinked, StatusConflict.
Status string
OnPath bool
// ExistingKind / ExistingTarget describe a conflict (or the current link).
// Kind is "symlink", "file", "directory", or "other".
ExistingKind string
ExistingTarget string // absolute path for symlinks; empty otherwise
// Method is MethodSymlink or MethodCopy. Set by ResolveFor from goos.
Method string
}
Plan is the result of Resolve: where to install, what is there, and whether the install directory is already on PATH.
func ResolveFor ¶ added in v0.16.0
ResolveFor picks the install directory and inspects Dest. goos is an explicit GOOS value so the Windows dest name and copy/symlink choice can be tested on any host (callers pass runtime.GOOS in production).
dirFlag empty → DefaultDir(pathEnv) heuristic. Non-empty → expand/absolutize that path and skip the heuristic. pathEnv is the PATH string (usually os.Getenv("PATH")); inject a fake value in tests.
func (Plan) AlreadyInstalledLine ¶ added in v0.16.0
AlreadyInstalledLine is printed when Status is already linked/copied.
func (Plan) InstalledLine ¶ added in v0.16.0
InstalledLine is printed after a successful Install.
func (Plan) PrintStatusLine ¶ added in v0.16.0
PrintStatusLine is the `gadak install-cli --print` status line. Ownership lives here so the CLI cannot drift into saying "symlink" for a copy.