|
| 1 | +package config |
| 2 | + |
| 3 | +import ( |
| 4 | + "cosmossdk.io/errors" |
| 5 | + goGitConfig "github.com/go-git/go-git/v5/config" |
| 6 | +) |
| 7 | + |
| 8 | +const ( |
| 9 | + AppName = "git-remote-gitopia" |
| 10 | + 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 | +) |
| 20 | + |
| 21 | +func LoadGitConfig() error { |
| 22 | + conf, err := goGitConfig.LoadConfig(goGitConfig.GlobalScope) |
| 23 | + if err != nil { |
| 24 | + return errors.Wrap(err, "error loading git config") |
| 25 | + } |
| 26 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 27 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigChainid) { |
| 28 | + ChainId = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigChainid) |
| 29 | + } |
| 30 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 31 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGrpchost) { |
| 32 | + GRPCHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGrpchost) |
| 33 | + } |
| 34 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 35 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGitserverhost) { |
| 36 | + GitServerHost = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGitserverhost) |
| 37 | + } |
| 38 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 39 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigTmaddr) { |
| 40 | + TmAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigTmaddr) |
| 41 | + } |
| 42 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 43 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigGasprices) { |
| 44 | + GasPrices = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigGasprices) |
| 45 | + } |
| 46 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 47 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigFeegranter) { |
| 48 | + FeeGranterAddr = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigFeegranter) |
| 49 | + } |
| 50 | + if conf.Raw.HasSection(gitopiaConfigSection) && |
| 51 | + conf.Raw.Section(gitopiaConfigSection).HasOption(gitopiaConfigDenom) { |
| 52 | + Denom = conf.Raw.Section(gitopiaConfigSection).Option(gitopiaConfigDenom) |
| 53 | + } |
| 54 | + return nil |
| 55 | +} |
0 commit comments