conf

package
v0.22.2 Latest Latest
Warning

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

Go to latest
Published: Mar 23, 2024 License: MIT Imports: 14 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

View Source
var (
	ErrUnsetHOME       = errors.New("HOME environment variable unset")
	ErrRepoNotAbs      = errors.New("repository path must be absolute")
	ErrRepoUnset       = errors.New("repository path must be set in configuration")
	ErrProfileRequired = errors.New("profile must be specified or default profile set")
	ErrProfileUnknown  = errors.New("specified profile not found")
)
View Source
var ConfigurationTmpl = template.Must(template.New("config").Funcs(template.FuncMap{
	"printt": printt,
}).Parse(`# repoctl configuration

# columnate specifies that listings should be in columns rather than
# in lines. This only applies to the list command.
columnate = {{ printt .Columnate }}

# color specifies when to use color. Can be one of auto, always, and never.
color = {{ printt .Color }}

# quiet specifies whether repoctl should print more information or less.
# I prefer to know what happens, but if you don't like it, you can change it.
quiet = {{ printt .Quiet }}

# default_profile specifies which profile should be used when none is
# specified on the command line.
default_profile = {{ printt .DefaultProfile }}

{{ range $key, $value := .Profiles }}[profiles.{{  $key }}]
  # repo is the full path to the repository that will be managed by repoctl.
  # The packages that belong to the repository are assumed to lie in the
  # same folder.
  repo = {{ printt $value.Repository }}

  # add_params is the set of parameters that will be passed to repo-add
  # when it is called. Specify one time for each parameter.
  add_params = {{ printt $value.AddParameters }}

  # rm_params is the set of parameters that will be passed to repo-remove
  # when it is called. Specify one time for each parameter.
  rm_params = {{ printt $value.RemoveParameters }}

  # ignore_aur is a set of package names that are ignored in conjunction
  # with AUR related tasks, such as determining if there is an update or not.
  ignore_aur = {{ printt $value.IgnoreAUR }}

  # require_signature prevents packages from being added that do not
  # also have a signature file.
  require_signature = {{ printt $value.RequireSignature }}

  # backup specifies whether package files should be backed up or deleted.
  # If it is set to false, then obsolete package files are deleted.
  backup = {{ printt $value.Backup }}

  # backup_dir specifies which directory backups are stored in.
  # - If a relative path is given, then it is interpreted as relative to
  #   the repository directory.
  # - If the path here resolves to the same as repo, then obsolete packages
  #   are effectively ignored by repoctl, if backup is true.
  backup_dir = {{ printt $value.BackupDir }}

  # interactive specifies that repoctl should ask before doing anything
  # destructive.
  interactive = {{ printt $value.Interactive }}

  # pre_action is a command that should be executed before doing anything
  # with the repository, like reading or modifying it. Useful for mounting
  # a remote filesystem.
  pre_action = {{printt $value.PreAction}}

  # post_action is a command that should be executed before exiting.
  post_action = {{ printt $value.PostAction }}
{{ end }}
`))
View Source
var PropertiesTmpl = template.Must(template.New("properties").Funcs(template.FuncMap{
	"printt": printt,
}).Parse(`Current configuration:
    columnate = {{ printt .Columnate }}
    color = {{ printt .Color }}
    quiet = {{ printt .Quiet }}

    current_profile = {{ printt .CurrentProfile }}
    default_profile = {{ printt .DefaultProfile }}
    {{ range $key, $value := .Profiles }}
    [profiles.{{  $key }}]
        repo = {{ printt $value.Repository }}
        add_params = {{ printt $value.AddParameters }}
        rm_params = {{ printt $value.RemoveParameters }}
        ignore_aur = {{ printt $value.IgnoreAUR }}
        require_signature = {{ printt $value.RequireSignature }}
        backup = {{ printt $value.Backup }}
        backup_dir = {{ printt $value.BackupDir }}
        interactive = {{ printt $value.Interactive }}
        pre_action = {{printt $value.PreAction}}
        post_action = {{ printt $value.PostAction }}
    {{ end }}
`))

Functions

func HomeConf

func HomeConf() string

HomeConf is the path to the home configuration file, which we can write to.

If REPOCTL_CONFIG is set, then HomeConf points to that.

Types

type Configuration

type Configuration struct {
	// Columnate causes items to be printed in columns rather than lines.
	Columnate bool `toml:"columnate"`

	// Color causes repoctl output to be colorized.
	Color string `toml:"color"`

	// Quiet causes less information to be printed than usual.
	Quiet bool `toml:"quiet"`

	// When Debug is specified, it presides over Quiet.
	// This allows it to override a possible default value of Quiet.
	Debug bool `toml:"-"`

	// When CurrentProfile is specified, it presides over DefaultProfile.
	// This allows it to override the default, and is what we use for
	// profile selection from the command line.
	CurrentProfile string `toml:"-"`

	// DefaultProfile to use when no other profile is specified.
	DefaultProfile string `toml:"default_profile"`

	Profiles map[string]*Profile `toml:"profiles"`
}

func Default

func Default() *Configuration

Default acts as the default configuraton and contains no profiles.

func FindAll

func FindAll() (*Configuration, error)

FindAll loads all configuration files it finds in the search path.

  • If REPOCTL_CONFIG is set, this function will only use the path specified in that variable.

func New

func New(repo string) *Configuration

New creates a new configuration with a default profile.

func Read

func Read(filepath string) (*Configuration, error)

Read creates a new configuration by reading one from the specified path.

func (*Configuration) GetProfile

func (c *Configuration) GetProfile(name string) (*Profile, error)

func (*Configuration) MergeFile

func (c *Configuration) MergeFile(filepath string) error

MergeFile merges the contents of a file into the configuration here.

It will warn the user on the use of deprecated fields, and it will also auto-migrate old configuration files.

func (*Configuration) SelectProfile

func (c *Configuration) SelectProfile() (*Profile, string, error)

SelectProfile returns the current "selected" profile.

- CurrentProfile has priority over DefaultProfile. - If no profile is selected, then (nil, "", nil) is returned. - An error is only returned if a profile is selected but is not available.

Before using the profile for the first time, make sure you call the profile Init() method.

func (*Configuration) WriteFile

func (c *Configuration) WriteFile(filepath string) error

func (*Configuration) WriteProperties

func (c *Configuration) WriteProperties(w io.Writer) error

func (*Configuration) WriteTemplate

func (c *Configuration) WriteTemplate(w io.Writer) error

type Profile

type Profile struct {
	// Repository is the absolute path to the database. We assume that this is
	// also where the packages are. The variables database and path are constructed
	// from this.
	Repository string `toml:"repo"`

	// AddParameters are parameters to add to the repo-add command line.
	AddParameters []string `toml:"add_params"`
	// RemoveParameters are parameters to add to the repo-remove command line.
	RemoveParameters []string `toml:"rm_params"`
	// Packages to ignore when doing AUR related tasks.
	IgnoreAUR []string `toml:"ignore_aur"`
	// Require signatures for packages that are added to the database.
	RequireSignature bool `toml:"require_signature"`

	// Backup causes older packages to be backed up rather than deleted.
	Backup bool `toml:"backup"`
	// BackupDir specifies where old packages are backed up to.
	BackupDir string `toml:"backup_dir"`
	// Interactive requires confirmation before deleting and changing the
	// repository database.
	Interactive bool `toml:"interactive"`

	// PreAction and PostAction are run every time that the database or
	// filesystem is accessed.
	PreAction  string `toml:"pre_action"`
	PostAction string `toml:"post_action"`
	// contains filtered or unexported fields
}

Profile doubles as configuration file format and the global configuration set.

func DefaultProfile

func DefaultProfile() *Profile

func NewProfile

func NewProfile(repo string) *Profile

NewProfile creates a new default configuration with repo as the repository database.

If repo is invalid (because it is absolute), nil is returned. We don't check for existance, because at this point, it might not exist yet.

func (*Profile) Init

func (p *Profile) Init() error

Init should be called every time after changing c.Repository. This ensures that the configuration is both valid and consistent.

If the repository path is not absolute, ErrRepoNotAbs is returned.

Jump to

Keyboard shortcuts

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