Skip to content

Commit

Permalink
Strip optimization
Browse files Browse the repository at this point in the history
  • Loading branch information
firmanmm committed Dec 20, 2020
1 parent 79f8d6e commit 82fc044
Show file tree
Hide file tree
Showing 4 changed files with 10 additions and 7 deletions.
1 change: 1 addition & 0 deletions cmd/gomp/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,7 @@ func main() {
cliApp.Usage = "Go Module for Private Git Server Repository"
cliApp.Description = "Allow you to use Git Private Server as your source dependency while using Go Module"
cliApp.Author = `Firman "Rendoru" Maulana`
cliApp.Version = "Alpha"
cliApp.Commands = []cli.Command{
getCmd.Init(),
addCredentialCmd.Init(),
Expand Down
4 changes: 2 additions & 2 deletions modfile_mod_updater.go
Original file line number Diff line number Diff line change
Expand Up @@ -35,10 +35,10 @@ func (g *ModfileModUpdater) Update(repositories []string) error {
}
for path, val := range repoMap {
if val {
if err := parsedFile.AddRequire(path, "v.gomp"); err != nil {
if err := parsedFile.AddRequire(path, "v0.0.0"); err != nil {
return err
}
if err := parsedFile.AddReplace(path, "v.gomp", "./.vendor.gomp/"+path, ""); err != nil {
if err := parsedFile.AddReplace(path, "v0.0.0", "./.vendor.gomp/"+path, ""); err != nil {
return err
}
}
Expand Down
2 changes: 1 addition & 1 deletion modfile_mod_updater_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ func TestModfileModUpdater_Update(t *testing.T) {
finalRead := string(rawFinalRead)
for _, repo := range tt.args.repositories {
assert.Contains(t, finalRead, repo)
assert.Contains(t, finalRead, fmt.Sprintf("%s v.gomp => ./.vendor.gomp/%s", repo, repo))
assert.Contains(t, finalRead, fmt.Sprintf("%s v0.0.0 => ./.vendor.gomp/%s", repo, repo))
}
})
}
Expand Down
10 changes: 6 additions & 4 deletions setting.go
Original file line number Diff line number Diff line change
Expand Up @@ -67,10 +67,12 @@ func (s *Setting) AddCredential(matcher, host, username, basePath string) error
}

func (s *Setting) AddRepository(name string) error {
if idx := sort.SearchStrings(s.data.PrivateRepositories, name); idx == len(s.data.PrivateRepositories) {
s.data.PrivateRepositories = append(s.data.PrivateRepositories, name)
sort.Sort(stringSort(s.data.PrivateRepositories))
for _, repo := range s.data.PrivateRepositories {
if repo == name {
return nil
}
}
s.data.PrivateRepositories = append(s.data.PrivateRepositories, name)
return s.modUpdater.Update(s.data.PrivateRepositories)
}

Expand Down Expand Up @@ -114,7 +116,7 @@ func (s *Setting) LoadFromFile(fileName string) error {
func NewSetting() *Setting {
instance := new(Setting)
instance.data = NewSettingData()
instance.modUpdater = NewRegexModUpdater()
instance.modUpdater = NewModfileModUpdater()
return instance
}

Expand Down

0 comments on commit 82fc044

Please sign in to comment.