config

package
v0.1.1 Latest Latest
Warning

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

Go to latest
Published: Aug 22, 2026 License: MIT Imports: 7 Imported by: 0 modules, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package config reads and writes the CLI's profile file.

The file lives under the OS configuration directory ( $XDG_CONFIG_HOME/ht-cli/config.yaml on Linux, ~/Library/Application Support/ht-cli/config.yaml on macOS, %AppData%\ht-cli\config.yaml on Windows) and is written 0600, because it holds API tokens.

Index

Constants

View Source
const DefaultProfile = "default"

DefaultProfile is the profile used when none is named.

View Source
const EnvConfigDir = "HT_CONFIG_DIR"

EnvConfigDir overrides where the configuration file is looked for.

Variables

View Source
var Settable = []string{"token", "base-url", "output"}

Settable is the list of keys `ht-cli config set` accepts, in help order.

Functions

func Dir

func Dir() (string, error)

Dir is the directory the configuration file lives in.

func Path

func Path() (string, error)

Path is the full path of the configuration file.

func Redact

func Redact(token string) string

Redact replaces all but the last four characters of a token, so a status line can prove which credential is in use without printing it.

Types

type File

type File struct {
	// Current is the profile used when --profile is not given.
	Current string `yaml:"current,omitempty"`
	// Profiles is the named profiles, keyed by name.
	Profiles map[string]Profile `yaml:"profiles,omitempty"`
	// contains filtered or unexported fields
}

File is the whole configuration document.

func Load

func Load() (*File, error)

Load reads the configuration file. A missing file is not an error: it yields an empty document that Save will create.

func (*File) FilePath

func (f *File) FilePath() string

FilePath is where this document was read from or will be written to.

func (*File) Names

func (f *File) Names() []string

Names lists the profile names in alphabetical order.

func (*File) Put

func (f *File) Put(name string, p Profile)

Put stores a profile under name and makes it current when the file had no current profile yet.

func (*File) Remove

func (f *File) Remove(name string) bool

Remove deletes a profile and reports whether it existed.

func (*File) Resolve

func (f *File) Resolve(name string) (string, Profile)

Resolve returns the named profile, or the current one when name is empty. A profile that does not exist yet reads as empty, so a fresh installation works before `ht-cli auth login` has run.

func (*File) Save

func (f *File) Save() error

Save writes the configuration file, creating its directory and keeping both 0700 and 0600 so a token is never world-readable.

type Profile

type Profile struct {
	Token   string `yaml:"token,omitempty"`
	BaseURL string `yaml:"base-url,omitempty"`
	Output  string `yaml:"output,omitempty"`
}

Profile is one named set of settings.

func (Profile) Get

func (p Profile) Get(key string) (string, error)

Get reads one settable key off a profile.

func (*Profile) Set

func (p *Profile) Set(key, value string) error

Set writes one settable key on a profile.

Jump to

Keyboard shortcuts

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