This repository has been archived by the owner on Sep 2, 2022. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 0
/
config.go
98 lines (76 loc) · 2.35 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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
package main
import (
"os"
"github.com/pirmd/gostore/modules"
"github.com/pirmd/gostore/store"
"github.com/pirmd/gostore/ui/cli"
)
// Config represents the configuration for gostore.
type Config struct {
// Verbose is a flag that governs if log information are to be shown
Verbose bool
// Debug is a flag that governs if debug information are to be shown
Debug bool
// ReadOnly is the flag to switch the store into read only operation mode
ReadOnly bool
// DeleteGhosts is a flag that instructs gostore.Check to delete any
// database entries that does not correspond to an existing file in the
// store's filesystem (so called ghost record)
DeleteGhosts bool
// DeleteOrphans is a flag that instructs gostore.Check to delete any
// file of the store's filesystem that is not recorded in the store's
// database.
DeleteOrphans bool
// ImportOrphans is a flag that instructs gostore.Check to re-import any
// file of the store's filesystem that is not recorded in the store's
// database.
ImportOrphans bool
// Store contains configuration for anything related to storage
Store *store.Config
// UI contains configuration for anything related to user interface
UI *cli.Config
// Import list of actions to apply when importing a record
Import []*moduleConfig
// Update list of actions to apply when importing a record
Update []*moduleConfig
}
// Modules lists available modules.
func (cfg *Config) Modules() []string {
return modules.List()
}
// Analyzers lists available analyzers for indexing records.
func (cfg *Config) Analyzers() []string {
return cfg.Store.Analyzers()
}
// Styles lists available styles for printing records.
func (cfg *Config) Styles() []string {
return cfg.UI.Styles()
}
func (cfg *Config) expandEnv() {
cfg.Store.Path = os.ExpandEnv(cfg.Store.Path)
cfg.UI.EditorCmd = os.ExpandEnv(cfg.UI.EditorCmd)
cfg.UI.MergerCmd = os.ExpandEnv(cfg.UI.MergerCmd)
}
func newConfig() *Config {
return &Config{
Store: store.NewConfig(),
UI: cli.NewConfig(),
}
}
type moduleConfig struct {
Name string
Config *rawYAMLConfig
}
type rawYAMLConfig struct {
unmarshal func(interface{}) error
}
func (cfg *rawYAMLConfig) UnmarshalYAML(unmarshal func(interface{}) error) error {
cfg.unmarshal = unmarshal
return nil
}
func (cfg *rawYAMLConfig) Unmarshal(v interface{}) error {
if cfg == nil {
return nil
}
return cfg.unmarshal(v)
}