configuration

package
v0.1.0 Latest Latest
Warning

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

Go to latest
Published: Feb 29, 2024 License: AGPL-3.0 Imports: 18 Imported by: 0

Documentation

Index

Constants

View Source
const ErrConfigDoesNotExistMsg = "No configuration exists.\nRun `gin config add` to add remotes"

Variables

View Source
var ErrConfigDoesNotExist = errors.New("config does not exist")

ErrConfigDoesNotExist is returned by Load if no configuration file exists.

View Source
var ErrUpdateSameValues = errors.New("called update config with existing values")

ErrUpdateSameValues is returned if Update was called with the same url and token that is already stored in the configuration file.

Functions

func Append

func Append(urlStr string, token string, remoteType rt.Type) error

Append adds the token to the corresponding host in the configuration file. If no configuration file exists, a new one will be created.

func List

func List() error

List prints all stored remotes.

func Remove

func Remove(config *Config, configIndex int, detailsIndex int) error

Remove removes the token/url combination at the passed indices.

func Update

func Update(config *Config, configIndex int, detailsIndex int, url string, token string) error

Update updates the token/url and checks the token's validity.

func UpdateColors

func UpdateColors(c Colors, config *Config) error

UpdateColors sets the colors in the configuration to the provided values and writes the updated configuration back.

func UpdateRemote

func UpdateRemote() error

UpdateRemote loads the configuration file and updates the username and token name associated with each token.

func VerifyTokens

func VerifyTokens() error

VerifyTokens loads the configuration file and checks if every token is valid.

Types

type Colors

type Colors struct {
	Blurred string
	Border  string
	Focused string
}

Colors contains hex strings of colors for the different styles.

func (*Colors) CheckValidity

func (c *Colors) CheckValidity() error

CheckValidity checks if the colors in the struct are valid hex strings. Empty strings are ignored.

type Config

type Config struct {
	Colors  Colors
	Remotes []Remote
	Version uint8
}

Config contains the Colors configurations, a Version number and a list of Remotes.

func Load

func Load() (*Config, error)

Load returns the config located at '~/.config/gin/config.toml' if it exists. If it does not exist, function returns a ErrConfigDoesNotExist error and an initialized Config.

func (*Config) GetMatchingConfig

func (config *Config) GetMatchingConfig(details []repository.Details) (*match.Match, string, error)

GetMatchingConfig searches the config's Remotes and returns a remote.Match if a Remote has the same URL as one of the passed repository.Details.

type Remote

type Remote struct {
	URL     url.URL
	Details []remote.Details
	Type    rt.Type
}

Remote contains the remote's URL and a list of Details, containing the token, username and token name.

func (*Remote) ToMatch

func (r *Remote) ToMatch() (*match.Match, error)

ToMatch casts the remote to a remote.Match if the remote contains one Details. An error is returned if there are none or more than one Details.

func (*Remote) ToMatchAtIndex

func (r *Remote) ToMatchAtIndex(index int) (*match.Match, error)

ToMatchAtIndex casts the remote at index to a remote.Match.

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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