Documentation
¶
Overview ¶
Package helper provides configuration, filesystem, and terminal helpers used by projecto.
Index ¶
- Variables
- func CheckError(e error)
- func ConfigDir() (string, error)
- func ConfigFileExists(path string) bool
- func ConfigPath() (string, error)
- func CurrentDir() (string, string)
- func DefaultEditor() string
- func DirName(path string) string
- func MigrateLegacyConfig() (bool, error)
- func OpenConfigFile()
- func ResolveDir(dir string) (string, string, error)
- func ShortenHome(path string) string
- func WriteConfigFile(config Projecto, configDir string)
- type Project
- type Projecto
Constants ¶
This section is empty.
Variables ¶
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
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 ¶
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
ConfigPath returns the full path of the projecto configuration file inside ConfigDir.
func CurrentDir ¶
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
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
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
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
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 ¶
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 ¶
ReadConfigFile reads and parses the projecto configuration file from the given configuration directory.