This repository has been archived by the owner on Jan 16, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
/
config.go
65 lines (49 loc) · 1.38 KB
/
config.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
// config.go contains functions that interact with the config file, this is a
// file called `config.toml` found in `/etc/prt/`.
package main
import (
"fmt"
"github.com/BurntSushi/toml"
"github.com/fatih/color"
"github.com/onodera-punpun/prt/ports"
)
// config is a stuct with all config values. See `runtime/config/config.toml`
// for more information about these values.
var config struct {
PrtDir string
PkgDir string
SrcDir string
WrkDir string
Order []string
Aliases [][]ports.Location
ConcurrentDownloads int
IndentChar string
WarningChar string
DarkColor color.Attribute
LightColor color.Attribute
WarningColor color.Attribute
Repo map[string]repo
}
// pull is a struct with values related to repos.
type repo struct {
URL string
Branch string
}
var dark, light, warning func(a ...interface{}) string
// pareConfig parses a toml config.
func parseConfig() error {
_, err := toml.DecodeFile("/etc/prt/config.toml", &config)
if err != nil {
return fmt.Errorf("config /etc/prt/config.toml: " + err.Error())
}
ports.PrtDir = config.PrtDir
ports.PkgDir = config.PkgDir
ports.SrcDir = config.SrcDir
ports.WrkDir = config.WrkDir
ports.Order = config.Order
ports.Aliases = config.Aliases
dark = color.New(config.DarkColor).SprintFunc()
light = color.New(config.LightColor).SprintFunc()
warning = color.New(config.WarningColor).SprintFunc()
return nil
}