clitool

package
v0.15.0 Latest Latest
Warning

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

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

Documentation

Overview

Package clitool installs the gadak binary onto PATH via a symlink. Shared by `gadak install-cli` and the desktop "Install Command Line Tool…" menu so both surfaces use the same resolve / install / PATH-advice logic.

Index

Constants

View Source
const (
	StatusMissing  = "missing"  // nothing at Dest
	StatusLinked   = "linked"   // Dest is already a symlink to Source
	StatusConflict = "conflict" // Dest exists but is not the desired link
)

Destination status after Resolve.

Variables

This section is empty.

Functions

func DefaultDir

func DefaultDir(pathEnv string) (string, error)

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

Order (see comment block in the body):

  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)

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 symlinks Dest → Source. When Status is linked, Install is a no-op. When Status is conflict and force is false, Install returns an error without touching the filesystem. force replaces an existing Dest.

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).

func PathExportLine

func PathExportLine(dir, shell string) string

PathExportLine returns a one-liner the user can paste to add dir to PATH (clipboard / advisory). shell is typically os.Getenv("SHELL").

func ResolveDir

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

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

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
}

Plan is the result of Resolve: where to install, what is there, and whether the install directory is already on PATH.

func Resolve

func Resolve(source, dirFlag, pathEnv string) (Plan, error)

Resolve picks the install directory and inspects Dest.

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.

Jump to

Keyboard shortcuts

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