|
1 | 1 | package config |
2 | 2 |
|
3 | 3 | import ( |
4 | | - "cosmossdk.io/errors" |
5 | | - goGitConfig "github.com/go-git/go-git/v5/config" |
| 4 | + "fmt" |
| 5 | + "os/exec" |
| 6 | + "strings" |
6 | 7 | ) |
7 | 8 |
|
8 | 9 | const ( |
9 | 10 | AppName = "git-remote-gitopia" |
10 | 11 | gitopiaConfigSection = "gitopia" |
11 | | - |
12 | | - gitopiaConfigChainid = "chainid" |
13 | | - gitopiaConfigGrpchost = "grpchost" |
14 | | - gitopiaConfigGitserverhost = "gitserverhost" |
15 | | - gitopiaConfigTmaddr = "tmaddr" |
16 | | - gitopiaConfigGasprices = "gasprices" |
17 | | - gitopiaConfigFeegranter = "feegranter" |
18 | | - gitopiaConfigDenom = "denom" |
19 | 12 | ) |
20 | 13 |
|
21 | | -func LoadGitConfig() error { |
22 | | - conf, err := goGitConfig.LoadConfig(goGitConfig.GlobalScope) |
| 14 | +func gitConfigGet(key string) (string, error) { |
| 15 | + cmd := exec.Command("git", "config", "--get", fmt.Sprintf("gitopia.%s", key)) |
| 16 | + stdout, err := cmd.Output() |
| 17 | + |
23 | 18 | if err != nil { |
24 | | - return errors.Wrap(err, "error loading git config") |
| 19 | + return "", err |
25 | 20 | } |
26 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
27 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigChainid) { |
28 | | - ChainId = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigChainid) |
| 21 | + |
| 22 | + res := strings.TrimSpace(string(stdout)) |
| 23 | + return res, nil |
| 24 | +} |
| 25 | + |
| 26 | +func LoadGitConfig() error { |
| 27 | + if res, err := gitConfigGet("chainId"); err == nil { |
| 28 | + ChainId = res |
29 | 29 | } |
30 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
31 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGrpchost) { |
32 | | - GRPCHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGrpchost) |
| 30 | + if res, err := gitConfigGet("grpcHost"); err == nil { |
| 31 | + GRPCHost = res |
33 | 32 | } |
34 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
35 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGitserverhost) { |
36 | | - GitServerHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGitserverhost) |
| 33 | + if res, err := gitConfigGet("gitServerHost"); err == nil { |
| 34 | + GitServerHost = res |
37 | 35 | } |
38 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
39 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigTmaddr) { |
40 | | - TmAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigTmaddr) |
| 36 | + if res, err := gitConfigGet("tmAddr"); err == nil { |
| 37 | + TmAddr = res |
41 | 38 | } |
42 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
43 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGasprices) { |
44 | | - GasPrices = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGasprices) |
| 39 | + if res, err := gitConfigGet("gasPrices"); err == nil { |
| 40 | + GasPrices = res |
45 | 41 | } |
46 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
47 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigFeegranter) { |
48 | | - FeeGranterAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigFeegranter) |
| 42 | + if res, err := gitConfigGet("feeGranter"); err == nil { |
| 43 | + FeeGranterAddr = res |
49 | 44 | } |
50 | | - if conf.Raw.HasSection(gitopiaConfigSection) && |
51 | | - conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigDenom) { |
52 | | - Denom = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigDenom) |
| 45 | + if res, err := gitConfigGet("denom"); err == nil { |
| 46 | + Denom = res |
53 | 47 | } |
54 | 48 | return nil |
55 | 49 | } |
0 commit comments