Skip to content

Commit f996a7a

Browse files
committed
- v2.7.6
- Upgrade go-helper to v1.1.8 - Fix config logic - Fix debug logic - Fix receiver name
1 parent 577a0f5 commit f996a7a

File tree

7 files changed

+35
-41
lines changed

7 files changed

+35
-41
lines changed

README.md

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ Command line tool for easy mass configuration of git remotes, and working with G
55
### Table Of Content
66
<!-- TOC -->
77

8-
- [Table Of Content](#table-of-content)
98
- [Highlight](#highlight)
109
- [Push multiple repository](#push-multiple-repository)
1110
- [Set Archived](#set-archived)
@@ -387,6 +386,11 @@ https://github.com/J-Siu/go-mygit/releases
387386
- Consolidate repo*Func() to repoDo()
388387
- v2.7.5
389388
- Fix Github workflow
389+
- v2.7.6
390+
- Upgrade go-helper to v1.1.8
391+
- Fix config logic
392+
- Fix debug logic
393+
- Fix receiver name
390394
391395
### License
392396

cmd/root.go

Lines changed: 8 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,8 @@ var rootCmd = &cobra.Command{
3737
Short: `Git and Repo automation made easy.`,
3838
Version: lib.Version,
3939
PersistentPreRun: func(cmd *cobra.Command, args []string) {
40+
helper.Debug = lib.Flag.Debug
41+
helper.ReportDebug(&lib.Flag, "Flag", false, false)
4042
lib.Conf.Init()
4143
lib.Conf.MergeRemotes()
4244
},
@@ -54,33 +56,22 @@ func Execute() {
5456
func init() {
5557
cobra.OnInitialize(initConfig)
5658
rootCmd.PersistentFlags().BoolVarP(&lib.Flag.Debug, "debug", "d", false, "Enable debug")
57-
rootCmd.PersistentFlags().BoolVarP(&lib.Flag.NoSkip, "no-skip", "", false, "Don't skip empty output")
5859
rootCmd.PersistentFlags().BoolVarP(&lib.Flag.NoParallel, "no-parallel", "", false, "Don't process in parallel")
60+
rootCmd.PersistentFlags().BoolVarP(&lib.Flag.NoSkip, "no-skip", "", false, "Don't skip empty output")
5961
rootCmd.PersistentFlags().BoolVarP(&lib.Flag.NoTitle, "no-title", "", false, "Don't print title for most output")
6062
rootCmd.PersistentFlags().StringArrayVarP(&lib.Flag.Groups, "group", "g", nil, "Specify group")
6163
rootCmd.PersistentFlags().StringArrayVarP(&lib.Flag.Remotes, "remote", "r", nil, "Specify remotes")
62-
rootCmd.PersistentFlags().StringVar(&lib.Conf.File, "config", "", "config file (default is $HOME/.go-mygit.json)")
64+
rootCmd.PersistentFlags().StringVarP(&lib.Conf.FileConf, "config", "", lib.DefaultConfFile, "Config file")
6365
}
6466

6567
// initConfig reads in config file and ENV variables if set.
6668
func initConfig() {
67-
if lib.Conf.File != "" {
68-
// Use config file from the flag.
69-
viper.SetConfigFile(lib.Conf.File)
70-
} else {
71-
// Find home directory.
72-
home, err := os.UserHomeDir()
73-
cobra.CheckErr(err)
74-
75-
// Search config in home directory with name ".go-mygit" (without extension).
76-
viper.AddConfigPath(home)
77-
viper.SetConfigType("json")
78-
viper.SetConfigName(".go-mygit")
69+
viper.SetConfigType("json")
70+
if lib.Conf.FileConf == "" {
71+
lib.Conf.FileConf = lib.DefaultConfFile
7972
}
80-
73+
viper.SetConfigFile(helper.TildeEnvExpand(lib.Conf.FileConf))
8174
viper.AutomaticEnv() // read in environment variables that match
82-
83-
// If a config file is found, read it in.
8475
if err := viper.ReadInConfig(); err != nil {
8576
helper.Report(err.Error(), "", true, true)
8677
os.Exit(1)

cmd/rootPush.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -97,5 +97,4 @@ func init() {
9797
rootCmd.AddCommand(rootPushCmd)
9898
rootPushCmd.Flags().BoolVarP(&lib.Flag.PushAll, "all", "a", false, "Push all branches")
9999
rootPushCmd.Flags().BoolVarP(&lib.Flag.PushTag, "tags", "t", false, "Push with tags")
100-
// rootPushCmd.MarkFlagsMutuallyExclusive("all","tags")
101100
}

go.mod

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@ go 1.24.5
44

55
require (
66
github.com/J-Siu/go-gitapi v1.6.0
7-
github.com/J-Siu/go-helper v1.1.7
7+
github.com/J-Siu/go-helper v1.1.8
88
github.com/savaki/jq v0.0.0-20161209013833-0e6baecebbf8
99
github.com/spf13/cobra v1.6.1
1010
github.com/spf13/viper v1.15.0

go.sum

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -40,8 +40,8 @@ github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03
4040
github.com/BurntSushi/xgb v0.0.0-20160522181843-27f122750802/go.mod h1:IVnqGOEym/WlBOVXweHU+Q+/VP0lqqI8lqeDx9IjBqo=
4141
github.com/J-Siu/go-gitapi v1.6.0 h1:isHmvr961CGiDwonbeiE8u8JhpVNTFeXjAayni05iXo=
4242
github.com/J-Siu/go-gitapi v1.6.0/go.mod h1:ZAIYbQvsXvxTqiCD39nIbXV/j7bd+1pK3U2YNBJ+eXc=
43-
github.com/J-Siu/go-helper v1.1.7 h1:8POi+Lqkhs90fu0yMKC2qcnWMbN/woLbJvP9NrA6YMk=
44-
github.com/J-Siu/go-helper v1.1.7/go.mod h1:PkBVY3EdVhAPE29H1Mx+nz1j01ymxy91VZV7VwHlsbA=
43+
github.com/J-Siu/go-helper v1.1.8 h1:cF92obqG6QTKkNYA06luuURCHHn99dR6pDEzak6fQ4c=
44+
github.com/J-Siu/go-helper v1.1.8/go.mod h1:PkBVY3EdVhAPE29H1Mx+nz1j01ymxy91VZV7VwHlsbA=
4545
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
4646
github.com/chzyer/logex v1.1.10/go.mod h1:+Ywpsq7O8HXn0nuIou7OrIPyXbp3wmkHB+jjWRnGsAI=
4747
github.com/chzyer/readline v0.0.0-20180603132655-2972be24d48e/go.mod h1:nSuG5e5PlCu98SY8svDHJxuZscDgtXS6KTTbou5AhLI=

lib/conf.go

Lines changed: 17 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -31,55 +31,54 @@ import (
3131
)
3232

3333
/*
34-
File, Group, MergeRemotes are filled in at runtime
34+
- File, Group, MergeRemotes are filled in at runtime
3535
36-
Remotes, Secrets are read from config file by viper
36+
- Remotes, Secrets are read from config file by viper
3737
*/
3838
type TypeConf struct {
39-
File string `json:"-"`
39+
FileConf string `json:"-"`
4040
Groups Groups `json:"-"`
4141
Remotes Remotes `json:"remotes"`
4242
Secrets ConfSecrets `json:"secrets"`
4343
MergedRemotes Remotes `json:"-"`
4444
}
4545

4646
// Fill in conf struct from viper and extract all groups from `Remotes`
47-
func (self *TypeConf) Init() {
48-
helper.Debug = Flag.Debug
49-
self.File = viper.ConfigFileUsed()
50-
viper.Unmarshal(&self)
47+
func (conf *TypeConf) Init() {
48+
viper.Unmarshal(&conf)
49+
prefix := "TypeConf.Init"
50+
helper.ReportDebug(conf.FileConf, prefix+":Config file", false, true)
5151
// Fill in ConfGroup
52-
for _, r := range self.Remotes {
53-
self.Groups.Add(&r.Group)
52+
for _, r := range conf.Remotes {
53+
conf.Groups.Add(&r.Group)
5454
}
55-
helper.ReportDebug(&Conf.File, "", true, true)
56-
helper.ReportDebug(&Flag, "Flag", true, false)
55+
helper.ReportDebug(conf, prefix, false, true)
5756
}
5857

5958
// Calculate remotes base on flag
60-
func (self *TypeConf) MergeRemotes() {
59+
func (conf *TypeConf) MergeRemotes() {
6160
// Merge remote from flag "group"
6261
for _, g := range Flag.Groups {
6362
group := &g
64-
if self.Groups.Has(group) {
65-
self.MergedRemotes.AddArray(self.Remotes.GetByGroup(group))
63+
if conf.Groups.Has(group) {
64+
conf.MergedRemotes.AddArray(conf.Remotes.GetByGroup(group))
6665
} else {
6766
log.Fatal("Group not in config: " + g)
6867
os.Exit(1)
6968
}
7069
}
7170
// Merge remote from flag "remote"
7271
for _, r := range Flag.Remotes {
73-
if self.Remotes.Has(&r) {
74-
self.MergedRemotes.Add(self.Remotes.GetByName(&r))
72+
if conf.Remotes.Has(&r) {
73+
conf.MergedRemotes.Add(conf.Remotes.GetByName(&r))
7574
} else {
7675
log.Fatal("Remote not in config: " + r)
7776
os.Exit(1)
7877
}
7978
}
8079
// If no remote is specified from command line, use all remotes in config
81-
if len(self.MergedRemotes) == 0 {
82-
self.MergedRemotes = append(self.MergedRemotes, self.Remotes...)
80+
if len(conf.MergedRemotes) == 0 {
81+
conf.MergedRemotes = append(conf.MergedRemotes, conf.Remotes...)
8382
}
8483
helper.ReportDebug(&Conf.MergedRemotes, "Merged Remote", true, false)
8584
}

lib/global.go

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -36,5 +36,6 @@ var (
3636
)
3737

3838
const (
39-
Version = "v2.7.5"
39+
DefaultConfFile = "~/.go-mygit.json"
40+
Version = "v2.7.6"
4041
)

0 commit comments

Comments
 (0)