cli

package
v0.0.0-...-676fa8b Latest Latest
Warning

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

Go to latest
Published: May 5, 2026 License: MIT Imports: 28 Imported by: 0

Documentation

Overview

Package cli implements the cobra command tree for the pennywise binary.

Index

Constants

View Source
const ServiceLabel = "com.pennywise.app"

ServiceLabel is the canonical name across platforms — the launchd Label and the systemd unit name (sans .service). Reverse-DNS to avoid clashes with anything else the user might have installed.

Variables

This section is empty.

Functions

func Execute

func Execute() error

Execute runs the root command.

func ExecuteWithContext

func ExecuteWithContext(ctx context.Context) error

Allow the parent process to inject a context (e.g. for graceful shutdown).

func LingerEnabledOrDefault

func LingerEnabledOrDefault() (bool, error)

LingerEnabledOrDefault reports whether the current user has linger enabled (i.e. `loginctl enable-linger <user>`). Without lingering, systemd --user services only run while the user is interactively logged in — auto-restart-on-boot expectations break.

Returns false on any uncertainty (loginctl missing, permission error) so the caller errs on the side of nudging the user.

Types

type ServiceManager

type ServiceManager interface {
	// Install writes the service definition to disk, registers it with
	// the OS supervisor, and ensures it's running. Re-running Install
	// after an upgrade refreshes the service file and kickstarts the
	// process — so `go install` followed by `pennywise start` picks up
	// the new binary path automatically.
	Install(cfg config.Config, binPath string) error

	// Uninstall stops the running process, removes it from the OS
	// supervisor, and deletes the service definition file. Idempotent —
	// running on an already-uninstalled system is a no-op.
	Uninstall(cfg config.Config) error

	// Status reports whether the service is installed (definition file
	// present + registered) and whether the process is currently running.
	Status() (ServiceStatus, error)

	// PlatformName is "launchd", "systemd-user", etc. — used in user
	// messages so they know which supervisor manages Pennywise on this OS.
	PlatformName() string

	// ServiceFilePath returns the absolute path to the on-disk service
	// definition (plist or .service file). Useful for status output and
	// for users who want to inspect or hand-edit it.
	ServiceFilePath() string
}

ServiceManager hides the platform-specific bits behind one interface. macOS implements it via launchd LaunchAgents; Linux via systemd --user units; Windows returns a clear "use Task Scheduler" error from newServiceManager.

The contract is deliberately small. Install/Uninstall are idempotent — running them twice is a no-op (or a refresh, in Install's case). Status distinguishes installed-but-stopped from never-installed so the CLI surface can give a precise message.

type ServiceStatus

type ServiceStatus struct {
	Installed bool // service definition file exists + registered
	Running   bool // process currently alive
	PID       int  // 0 if not running or unknown
}

ServiceStatus is the platform-agnostic status payload.

Jump to

Keyboard shortcuts

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