config

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Dec 19, 2025 License: MIT Imports: 4 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Create

func Create(projectName string, hourlyRate float64) error

Create creates a new Config populated with projectName and hourlyRate and writes it to a ".tmporc" file in the current working directory ("./.tmporc"). If a ".tmporc" file already exists, Create returns an error and does not overwrite it. Any error encountered while saving the configuration is returned to the caller.

func CreateWithTemplate

func CreateWithTemplate(projectName string, hourlyRate float64, description string) error

CreateWithTemplate creates a new .tmporc file with a user-friendly format that includes all fields (even if empty) and helpful comments. This provides a better user experience by showing all available configuration options.

Types

type Config

type Config struct {
	ProjectName string  `yaml:"project_name"`
	HourlyRate  float64 `yaml:"hourly_rate,omitempty"`
	Description string  `yaml:"description,omitempty"`
}

Config represents the project's configuration as loaded from a YAML file. It contains identifying and billing information along with an optional description.

ProjectName is the human-readable name of the project. HourlyRate is the billable hourly rate for the project; when zero it will be omitted from YAML. Description is an optional free-form description of the project; when empty it will be omitted from YAML.

! IMPORTANT When adding new fields to this struct, also update configTemplate below. !

func FindAndLoad

func FindAndLoad() (*Config, string, error)

FindAndLoad searches upward from the current working directory for a file named ".tmporc". Starting at os.Getwd(), it ascends parent directories until it either finds the file or reaches the filesystem root.

If a ".tmporc" file is found, FindAndLoad calls Load(path) and returns the resulting *Config, the absolute path to the discovered file, and any error returned by Load. If Load returns an error the returned *Config may be nil.

If the current working directory cannot be determined, or if no ".tmporc" is found before reaching the root, FindAndLoad returns (nil, "", err) describing the failure.

func Load

func Load(path string) (*Config, error)

Load reads a YAML configuration file from the provided path and unmarshals it into a Config. It returns a pointer to the populated Config on success. If the file cannot be read or the contents cannot be parsed as YAML, Load returns a wrapped error describing the failure.

func (*Config) Save

func (c *Config) Save(path string) error

Save marshals the Config into YAML and writes it to the provided filesystem path. The configuration is encoded using yaml.Marshal and written with file mode 0644. If a file already exists at path it will be overwritten. An error is returned if marshaling fails or if writing the file to disk is unsuccessful.

Jump to

Keyboard shortcuts

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