/
config.go
73 lines (60 loc) · 1.66 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
66
67
68
69
70
71
72
73
package zsh
import (
"bytes"
"io"
"reflect"
"gopkg.in/yaml.v3"
"github.com/alex-held/devctl-kit/pkg/generation/banner"
"github.com/alex-held/devctl-kit/pkg/plugins"
)
type CompletionsSpec struct {
CLI map[string]string `yaml:"cli,omitempty"`
Command map[string]string `yaml:"command,omitempty"`
}
type Config struct {
*plugins.Context `yaml:"-"`
Vars map[string]string `yaml:"vars,omitempty"`
Exports map[string]string `yaml:"exports,omitempty"`
Aliases map[string]string `yaml:"aliases,omitempty"`
Completions CompletionsSpec `yaml:"completions,omitempty"`
}
func ReadConfigFile(r io.Reader) (f *Config, err error) {
b := &bytes.Buffer{}
if _, err = io.Copy(b, r); err != nil {
return nil, err
}
f = CreateConfig()
if err = yaml.Unmarshal(b.Bytes(), f); err != nil {
return nil, err
}
return f, nil
}
func (c *Config) DeepEqual(other *Config) bool {
cC := Config{
Context: nil,
Vars: c.Vars,
Exports: c.Exports,
Aliases: c.Aliases,
Completions: c.Completions,
}
otherC := Config{
Context: nil,
Vars: other.Vars,
Exports: other.Exports,
Aliases: other.Aliases,
Completions: other.Completions,
}
return reflect.DeepEqual(cC, otherC)
}
func (c *Config) TemplateConfigs() (cfgs map[string]interface{}) {
return map[string]interface{}{
"completions": CompletionsTmplData{
Header: banner.GenerateBanner("Completions", banner.KIND_SHELL),
COMPLETIONS_DIR: c.Pather.Config("zsh", "completions"),
CONFIGFILE: c.Pather.Config("zsh", "config.yaml"),
Completions: c.Completions,
},
"exports": c.Exports,
"aliases": c.Aliases,
}
}