helper

package
v1.2.5 Latest Latest
Warning

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

Go to latest
Published: Sep 16, 2026 License: GPL-3.0 Imports: 8 Imported by: 0

Documentation

Overview

Package helper provides configuration, filesystem, and terminal helpers used by projecto.

Index

Constants

This section is empty.

Variables

View Source
var (
	RED    = "\033[31m"
	GREEN  = "\033[32m"
	YELLOW = "\033[33m"
	BLUE   = "\033[34m"
	RESET  = "\033[0m"
)

ANSI color escape sequences used for terminal output.

Functions

func CheckError

func CheckError(e error)

CheckError terminates the program with the error message if e is not nil.

func ConfigDir added in v1.2.0

func ConfigDir() (string, error)

ConfigDir returns the directory where projecto stores its data, following the XDG Base Directory Specification: $XDG_CONFIG_HOME/projecto when XDG_CONFIG_HOME is set to an absolute path, otherwise the platform default with a "projecto" subdirectory appended (~/.config/projecto on Linux, ~/Library/Application Support/projecto on macOS, %AppData%\projecto on Windows).

func ConfigFileExists

func ConfigFileExists(path string) bool

ConfigFileExists reports whether the configuration file exists and is a regular file. Any other error is treated as "not exists".

func ConfigPath added in v1.0.1

func ConfigPath() (string, error)

ConfigPath returns the full path of the projecto configuration file inside ConfigDir.

func CurrentDir

func CurrentDir() (string, string)

CurrentDir returns the current working directory and its name. It calls log.Fatalln on failure, terminating the program.

func DefaultEditor added in v1.2.0

func DefaultEditor() string

DefaultEditor returns the editor command to use as the global default: the basename of $EDITOR when set, falling back to "code". The value is trimmed; arguments (e.g. "code --wait") are stripped because the editor is launched with the project path as its sole argument.

func DirName added in v1.0.1

func DirName(path string) string

DirName returns the last element of a path, for example "projecto" for both "/home/user/projecto" and "C:\\Users\\user\\projecto".

func MigrateLegacyConfig added in v1.2.0

func MigrateLegacyConfig() (bool, error)

MigrateLegacyConfig moves a configuration file from the pre-projecto subdirectory location (the user configuration directory root) to the current one, if the legacy file exists and the new one does not. It reports whether a migration was performed.

func OpenConfigFile

func OpenConfigFile()

OpenConfigFile opens the projecto configuration file with the OS default application. On Windows it uses cmd's start builtin; on Linux xdg-open; and on macOS open.

func ResolveDir added in v1.2.3

func ResolveDir(dir string) (string, string, error)

ResolveDir resolves the directory to register: dir when given (relative paths are made absolute, and the target must exist and be a directory), otherwise the current working directory. It returns the absolute path and its name.

func ShortenHome added in v1.2.2

func ShortenHome(path string) string

ShortenHome abbreviates the user's home directory prefix to "~" so paths read as "~/work/api-server". Paths outside the home directory are returned unchanged.

func WriteConfigFile

func WriteConfigFile(config Projecto, configDir string)

WriteConfigFile serializes the given configuration and writes it to the configuration file in the given directory in a single atomic write.

Types

type Project

type Project struct {
	Name       string `json:"name"`
	Path       string `json:"path"`
	Editor     string `json:"editor,omitempty"`
	LastOpened string `json:"lastOpened,omitempty"`
}

Project represents a single registered project directory.

type Projecto

type Projecto struct {
	CommandToOpen string    `json:"commandToOpen"`
	Projects      []Project `json:"projects"`
}

Projecto is the top-level configuration structure persisted to projecto.json.

func ReadConfigFile

func ReadConfigFile(configDir string) Projecto

ReadConfigFile reads and parses the projecto configuration file from the given configuration directory.

Jump to

Keyboard shortcuts

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