diff --git a/parse/mgconf.go b/parse/mgconf.go index a91433c..3654987 100644 --- a/parse/mgconf.go +++ b/parse/mgconf.go @@ -6,11 +6,18 @@ import ( "path/filepath" ) +// MGConfig is the struct that represents the mgconfig file +// It contains a slice of Repo structs and a map of aliases +// The aliases map is a map of strings to strings, where the key is the alias +// and the value is a command to be run type MGConfig struct { Repos []Repo Aliases map[string]string } +// GetRepoPaths returns a slice of strings containing the paths of the repos +// in the mgconfig file + func (m MGConfig) GetRepoPaths() []string { paths := []string{} for _, r := range m.Repos { @@ -19,6 +26,9 @@ func (m MGConfig) GetRepoPaths() []string { return paths } +// LoadMGConfig loads the mgconfig file from the XDG_CONFIG_HOME directory +// or from the default location of $HOME/.config/mgconfig +// If the file is not found, an error is returned func LoadMGConfig() (MGConfig, error) { var config MGConfig mgConf := os.Getenv("MGCONFIG") diff --git a/parse/myrepos.go b/parse/myrepos.go index 0dbda59..7e649e1 100644 --- a/parse/myrepos.go +++ b/parse/myrepos.go @@ -19,6 +19,8 @@ type Repo struct { Aliases map[string]string } +// GetRepoPaths returns a slice of strings containing the paths of all repos +// in the MRConfig struct func (m MRConfig) GetRepoPaths() []string { paths := []string{} for _, r := range m.Repos { @@ -27,6 +29,9 @@ func (m MRConfig) GetRepoPaths() []string { return paths } +// LoadMRConfig loads the mrconfig file from the user's home directory +// and returns a MRConfig struct +// TODO: load aliases into map instead of hardcoded Unregister prop func LoadMRConfig() (MRConfig, error) { home, err := os.UserHomeDir() if err != nil { diff --git a/parse/myrepos_test.go b/parse/myrepos_test.go new file mode 100644 index 0000000..95a560a --- /dev/null +++ b/parse/myrepos_test.go @@ -0,0 +1,16 @@ +package parse + +import "testing" + +func TestLoadMRConfig(t *testing.T) { + // test cases for LoadMRConfig + tests := []struct { + id string + }{} + + for _, test := range tests { + t.Run(test.id, func(t *testing.T) { + // TODO + }) + } +}