config

package
v1.0.2 Latest Latest
Warning

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

Go to latest
Published: Aug 31, 2026 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config manages named connection profiles stored under $XDG_CONFIG_HOME/rdsh (default ~/.config/rdsh), the same location scheme gh uses. os.UserConfigDir is deliberately avoided: on darwin it points to ~/Library/Application Support instead.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Dir

func Dir() (string, error)

Dir returns the rdsh config directory.

func Path

func Path() (string, error)

Path returns the config file path.

Types

type Config

type Config struct {
	ActiveProfile string             `yaml:"active_profile,omitempty"`
	Profiles      map[string]Profile `yaml:"profiles,omitempty"`
}

Config is the on-disk configuration.

func Load

func Load() (*Config, error)

Load reads the config file. A missing file is not an error and yields an empty config, so first-run commands can give their own guidance.

func (*Config) Save

func (c *Config) Save() error

Save writes the config file with 0600 permissions (0700 for the directory), enforcing the mode even when the file already exists with a looser one.

func (*Config) SetActive

func (c *Config) SetActive(name string) error

SetActive switches the active profile; the name must exist.

func (*Config) SetProfile

func (c *Config) SetProfile(name string, p Profile)

SetProfile adds or replaces a profile. The first profile ever saved becomes the active one.

type Connection

type Connection struct {
	URL        string
	APIKey     string
	DataSource string
}

Connection is a resolved set of credentials for talking to one Redash instance. DataSource may be empty (the run command then requires --data-source).

func Resolve

func Resolve(cfg *Config, profileFlag string) (Connection, error)

Resolve picks the connection to use. Precedence: the --profile flag (explicit, one invocation) > the RDSH_URL/RDSH_API_KEY pair > the profile set persistently by `profile use`. When --profile is given the environment is not consulted — an explicit flag must never lose silently to ambient state.

type Profile

type Profile struct {
	URL        string `yaml:"url"`
	APIKey     string `yaml:"api_key"`
	DataSource string `yaml:"data_source,omitempty"`
}

Profile is one named Redash connection.

func (*Profile) UnmarshalYAML

func (p *Profile) UnmarshalYAML(node *yaml.Node) error

UnmarshalYAML accepts data_source written as an unquoted integer (e.g. `data_source: 3`); hand-editing the config file is a supported workflow and a plain string field would reject that.

Jump to

Keyboard shortcuts

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