Documentation
¶
Overview ¶
Package etcaid implements a framework for configuration backup & restore of apps.
Index ¶
- func WriteApplicationConfig(config ApplicationConfig, w io.Writer) error
- type Application
- type ApplicationConfig
- type ApplicationError
- type Config
- type Controller
- func (c *Controller) Application(name string) (ApplicationConfig, error)
- func (c *Controller) ApplicationConfigPath(name string) (string, error)
- func (c *Controller) Applications() []ApplicationConfig
- func (c *Controller) BackupAll()
- func (c *Controller) CheckInit() bool
- func (c *Controller) Create(name string) (string, error)
- func (c *Controller) HomePath() string
- func (c *Controller) Init() error
- func (c *Controller) LoadApplications() error
- func (c *Controller) RestoreAll()
- func (c *Controller) XDGConfigPath() string
Constants ¶
This section is empty.
Variables ¶
This section is empty.
Functions ¶
func WriteApplicationConfig ¶
func WriteApplicationConfig(config ApplicationConfig, w io.Writer) error
WriteApplicationConfig accepts a writer and writes the ApplicationConfig on it. It returns an error if it fails.
Types ¶
type Application ¶
type Application struct {
// contains filtered or unexported fields
}
Application represents an application instance.
func NewApplication ¶
func NewApplication( config ApplicationConfig, homePath string, xdgConfigPath string, targetPath string, logger logger, ) *Application
NewApp constructs an instance of Application using ApplicationConfig, paths & a concrete instance of logger.
func (*Application) Backup ¶
func (a *Application) Backup()
Backup backups the application configuration relative to the target path. It assumes that your backup directory has been backed up externally (for example, git) and may overwrite files in case of conflict.
func (*Application) Config ¶
func (a *Application) Config() ApplicationConfig
Config returns the underlying config of an application.
func (*Application) Restore ¶
func (a *Application) Restore()
Restore restores the application configuration relative to the target path. It assumes that your backup directory has been backed up externally (for example, git) and may overwrite files in case of conflict.
type ApplicationConfig ¶
type ApplicationConfig struct {
Name string `toml:"-"` // Unique name of the application
Title string `toml:"title"` // Title of the application
HomePaths []string `toml:"home_paths"` // HomePaths is the list of source application file paths that exist relative to the user home directory
XDGConfigPaths []string `toml:"xdg_config_paths"` // XDGConfigPaths is the list of source application file paths that exist relative to the user XDG Config directory
}
ApplicationConfig is the configuration describing an application.
func ParseApplicationConfig ¶
func ParseApplicationConfig(r io.Reader) (ApplicationConfig, error)
ParseApplicationConfig accepts a reader and parses it into ApplicationConfig. It returns an error if it fails.
type ApplicationError ¶
ApplicationError records an error and the operation and that caused it.
func (*ApplicationError) Error ¶
func (e *ApplicationError) Error() string
func (*ApplicationError) Unwrap ¶
func (e *ApplicationError) Unwrap() error
type Controller ¶
type Controller struct {
// contains filtered or unexported fields
}
Controller represents the etcaid controller. External user interfaces such as CLI will invoke the controller for working with etcaid.
func NewController ¶
func NewController(homePath string, xdgConfigPath string, logger logger) *Controller
NewController constructs an instance of Controller using etcaid config path, user home path, xdg directory path ahd an instance of logger.
func (*Controller) Application ¶
func (c *Controller) Application(name string) (ApplicationConfig, error)
Application accepts an application name and returns the application configuration available.
func (*Controller) ApplicationConfigPath ¶
func (c *Controller) ApplicationConfigPath(name string) (string, error)
ApplicationConfigPath returns the path to application configuration file for an application with the given name. It returns the an error if it fails.
func (*Controller) Applications ¶
func (c *Controller) Applications() []ApplicationConfig
Applications returns the list of all application configurations available.
func (*Controller) BackupAll ¶
func (c *Controller) BackupAll()
BackupAll backs up all applications from their locations as defined by the application configuration. Backed up applications are available in the etcaid dir.
func (*Controller) CheckInit ¶
func (c *Controller) CheckInit() bool
CheckInit checks if etcaid has been initialized. It returns false if the etcaid directories don't exist in home or there's an error accessing the directories. Else, it returns true.
func (*Controller) Create ¶
func (c *Controller) Create(name string) (string, error)
Create creates a new application configuration file to be used for backups. It returns the path to this file, or an error if it fails.
func (*Controller) HomePath ¶
func (c *Controller) HomePath() string
Returns the home path used to initialize the controller.
func (*Controller) Init ¶
func (c *Controller) Init() error
Init initializes etcaid directories & configuration. It returns an error if it fails.
func (*Controller) LoadApplications ¶
func (c *Controller) LoadApplications() error
LoadApplications loads the application configurations from the application config files and makes the applications ready for further use.
func (*Controller) RestoreAll ¶
func (c *Controller) RestoreAll()
RestoreAll restores all applications from the etcaid dir to their locations as defined by the application configuration.
func (*Controller) XDGConfigPath ¶
func (c *Controller) XDGConfigPath() string
Returns the xdg config path used to initialize the controller.