clitool

package
v0.18.1 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Aug 26, 2026 License: Apache-2.0 Imports: 8 Imported by: 0

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

View Source
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.

View Source
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.

View Source
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

View Source
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.

View Source
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

func DefaultDir(pathEnv string) (string, error)

DefaultDir chooses an install directory when --dir is omitted.

func DefaultDirFor added in v0.17.0

func DefaultDirFor(pathEnv, goos string) (string, error)

DefaultDirFor is DefaultDir with an explicit GOOS so the Windows default can be tested on any host (same shape as installMethodFor).

Unix order:

  1. ~/.local/bin if it exists and is already on PATH
  2. /usr/local/bin if it is on PATH and writable without sudo
  3. ~/.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

func ExpandHome(p string) (string, error)

ExpandHome expands a leading ~ or ~/… using os.UserHomeDir. Other paths are returned cleaned as-is.

func Install

func Install(p Plan, force bool) error

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

func PathContains(pathEnv, dir string) bool

PathContains reports whether dir appears as a PATH entry (exact, after Clean). Empty entries are ignored. Leading ~ in pathEnv entries is expanded.

func PathExportAdvise

func PathExportAdvise(dir, shell string) (line, rc string)

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

func PathExportAdviseFor(dir, shell, goos string) (line, rc string)

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

func RaycastExtDir() (string, error)

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

func ResolveDir(dirFlag, pathEnv string) (string, error)

ResolveDir returns the absolute install directory. Empty flag → DefaultDir(pathEnv). Leading ~ is expanded.

func ResolveNPM added in v0.16.0

func ResolveNPM(look func(string) (string, error), present func(string) bool) (string, bool)

ResolveNPM is LookPath("npm"), then NPMFallbackPaths.

func TildeHome

func TildeHome(path string) string

TildeHome shortens an absolute path under the user's home to ~/… for display.

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

func ResolveFor(source, dirFlag, pathEnv, goos string) (Plan, error)

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

func (p Plan) AlreadyInstalledLine() string

AlreadyInstalledLine is printed when Status is already linked/copied.

func (Plan) InstalledLine added in v0.16.0

func (p Plan) InstalledLine() string

InstalledLine is printed after a successful Install.

func (Plan) PrintStatusLine added in v0.16.0

func (p Plan) PrintStatusLine() string

PrintStatusLine is the `gadak install-cli --print` status line. Ownership lives here so the CLI cannot drift into saying "symlink" for a copy.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL