settings

package
v0.22.0 Latest Latest
Warning

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

Go to latest
Published: Nov 13, 2024 License: MPL-2.0 Imports: 8 Imported by: 0

Documentation

Overview

Package settings contains the logic for reading, writing, associating profiles with a user's settings file. It also configures a Tharsis SDK client.

Index

Constants

View Source
const (

	// SettingsDirectoryName is the name of directory where settings reside.
	SettingsDirectoryName = ".tharsis"

	// SettingsFilename is the name of the settings file.
	SettingsFilename = "settings.json"

	// DefaultProfileName is the name of the default profile
	DefaultProfileName = "default"
)

Variables

View Source
var (

	// ErrNoSettings is a special error if settings file does not exist.
	ErrNoSettings = fmt.Errorf(noSettingsMessage)
)

Functions

func DefaultSettingsFilename

func DefaultSettingsFilename() (string, error)

DefaultSettingsFilename returns the OS-dependent path/name of the default settings file.

Types

type Profile

type Profile struct {
	Token      *string `json:"stateToken"`
	TharsisURL string  `json:"tharsisURL"`
}

Profile holds the contents of one profile from a settings file.

func (*Profile) GetSDKClient

func (p *Profile) GetSDKClient() (*tharsis.Client, error)

GetSDKClient returns a Tharsis SDK client based on the specified profile.

type Settings

type Settings struct {
	Profiles       map[string]Profile `json:"profiles"`
	CurrentProfile *Profile           `json:"-"` // This field is not persistent, do not write it out.
}

Settings holds the contents of one settings file and a pointer to the profile specified by the current command.

func ReadSettings

func ReadSettings(name *string) (*Settings, error)

ReadSettings reads the settings file. If no argument, it reads the default settings file: ~/.tharsis/settings.json

func (*Settings) SetCurrentProfile

func (s *Settings) SetCurrentProfile(profileName string) error

SetCurrentProfile sets the current profile pointer in a settings object.

func (*Settings) WriteSettingsFile

func (s *Settings) WriteSettingsFile(name *string) error

WriteSettingsFile reads the settings file. If no filename argument, it writes the default settings file: ~/.tharsis/settings.json

Jump to

Keyboard shortcuts

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