config

package
v0.0.0-...-dd95ca6 Latest Latest
Warning

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

Go to latest
Published: Nov 1, 2022 License: MIT Imports: 5 Imported by: 0

Documentation

Overview

Package config contains logic related to user config files.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetDirectory

func GetDirectory() (string, error)

GetDirectory returns the directory value defined in config.

Types

type Config

type Config struct {
	Directory string    `json:"directory"`
	Editor    string    `json:"editor"`
	Templates Templates `json:"templates"`
}

Config represents the options defined in the config file.

func Get

func Get() (Config, error)

Get fetches the config via viper and converts it to a config struct so it can be used properly.

type CtxKey

type CtxKey string

CtxKey is the type for the config that gets bound to the cobra context so config values can be accessed by cobra commands.

const ContextKey CtxKey = "config"

ContextKey is the key value required to access the cobra command context.

type Error

type Error uint

Error is the error type.

const (
	// ErrConfigNotFound is the error thrown when a config file cannot be found.
	ErrConfigNotFound Error = iota
	// ErrReadingConfigFile is the error thrown when the config file cannot be parsed.
	ErrReadingConfigFile
	// ErrUnmashallingJSON is the error thrown when the provided config file can't be unmarshalled.
	ErrUnmashallingJSON
)

func (Error) Error

func (e Error) Error() string

Error returns the string message for the given error.

type Template

type Template struct {
	CustomDateFormat string    `json:"custom_date_format,omitempty"`
	File             string    `json:"file"`
	NameFormat       string    `json:"name_format,omitempty"`
	OutputDir        string    `json:"output_dir"`
	SubTemplates     Templates `json:"sub_templates,omitempty"`
}

Template represents the config options for a custom template file used for template and sub templates.

func (Template) GetNumberOfSubTemplates

func (t Template) GetNumberOfSubTemplates() int

GetNumberOfSubTemplates returns the number of sub templates defined for a template.

func (Template) HasSubTemplates

func (t Template) HasSubTemplates() bool

HasSubTemplates checks if the Template struct has sub templates. SubTemplates are offered at the pointing of using a template to give a specific version of a file.

type Templates

type Templates map[string]Template

Templates represents the structure of a collection of templates.

func (Templates) First

func (ts Templates) First() Template

First is a convenience method to return the first template from the Templates map.

Jump to

Keyboard shortcuts

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