-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
49 lines (40 loc) · 923 Bytes
/
main.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
package main
import (
"fmt"
"io"
"os"
"strings"
"github.com/masonkmeyer/ignore/cmd"
"github.com/masonkmeyer/ignore/repository"
"github.com/spf13/viper"
)
func main() {
viper.SetConfigName(".ignore")
viper.AddConfigPath("$HOME")
viper.SetConfigType("yaml")
viper.SetDefault("aliases", make(map[string]string))
if err := getOrCreateConfig(); err != nil {
io.Copy(os.Stderr, strings.NewReader(err.Error()))
return
}
provider := repository.NewGitProvider()
fetch := cmd.NewFetchCmd(provider)
alias := cmd.NewAliasCmd()
cmd.Run(fetch, alias)
}
func getOrCreateConfig() error {
if err := viper.ReadInConfig(); err != nil {
if err, ok := err.(viper.ConfigFileNotFoundError); ok {
dirname, err := os.UserHomeDir()
if err != nil {
return err
}
if _, err := os.Create(fmt.Sprintf("%s/.ignore", dirname)); err != nil {
return err
}
} else {
return err
}
}
return nil
}