config

package
v0.0.0-...-b355e5a Latest Latest
Warning

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

Go to latest
Published: Jun 23, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Overview

Package config handles configuration files. Files are stored in a directory inside user's HOME. HOME is identified by using github.com/mitchellh/go-homedir.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Backup

func Backup(filename string) error

Backup creates a zip file from the "homedir/borrowedtime/templates" directory and stores it in the "homedir/borrowedtime/backups" directory. Go's zip directory is very basic so we use: https://github.com/mholt/archiver. If input is empty, file name will be timestamp.

func BackupFiles

func BackupFiles() (fi []string, err error)

BackupFiles returns all files in the backup directory.

func ConfigDir

func ConfigDir() (string, error)

ConfigDir is the exported version of configDir.

func ConfigFilePath

func ConfigFilePath() (string, error)

ConfigFilePath returns the path of the config file.

func CreateDefault

func CreateDefault() error

CreateDefault creates the default config file and overwrites whatever is at "borrowedtime/config.json", finally opens it with OS default editor.

func Deploy

func Deploy() error

Deploy calls initiateConfig() to create the configuration structure and file. Returns an error if config already exists.

func Edit

func Edit(editor string) error

Edit attempts to open the config file and the borrowed time directory with editor.

func FileTemplates

func FileTemplates() (mp map[string]string, err error)

FileTemplates returns returns map[filename]fullpath of all files inside the file template directory.

func ProjectTemplates

func ProjectTemplates() (mp map[string]string, err error)

ProjectTemplates returns returns map[filename]fullpath of all files inside the project template directory.

func Reset

func Reset(createBackup bool, backupFile string) error

Reset creates a backup and then calls initiateConfig(overwrite=true) and overwrites deployment. If no backup filename is provided, it will create one based on timestamp.

func Restore

func Restore(filename string) error

Restore restores config.json and the templates directory from a backup file. Don't provide fullpath, just filename and extension.

func TemplatePath

func TemplatePath(name string) (string, error)

TemplatePath returns template path. Returns "" if the template does not exist. Template names should be passed without the extension. TODO: Make private.

func Write

func Write(cfg ConfigMap) error

Write writes the config in map[string]string to the config file.

Types

type ConfigMap

type ConfigMap map[string]string

ConfigMap represents the contents of the config file.

func Read

func Read() (ConfigMap, error)

Read reads the configuration file at "homedir/borrowedtime/config.json" and returns a populated map[string]string of keys.

func (ConfigMap) Has

func (v ConfigMap) Has(key string) bool

Has returns true if a key exists in the config.

func (ConfigMap) Key

func (v ConfigMap) Key(key string) string

Key returns the value of a key or "" if it does not exist in the config.

func (ConfigMap) Set

func (v ConfigMap) Set(key, value string)

Set assigns the value to the key in the config. It overwrites any previous values so if needed, check with Has first.

type Template

type Template struct {
	Name     string `json:"name"`
	FullPath string `json:"fullpath"`
}

Template represents one template.

Jump to

Keyboard shortcuts

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