Documentation
¶
Index ¶
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func Create ¶
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 ¶
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 ¶
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 ¶
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 ¶
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.