summaryrefslogtreecommitdiff
path: root/findRepos.go
blob: 18ddd03ba7dc8ed01cdb461a4c5c60108ad1e1f3 (plain)
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
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
package main

import (
	"go.wit.com/log"
)

func findRepos() bool {
	var done bool = false
	if argv.FindAll {
		findAll()
		done = true
	}

	if argv.FindPrivate {
		findPrivate()
		done = true
	}

	if argv.FindMine {
		findMine()
		done = true
	}
	if argv.FindFavorites {
		findFavorites()
		done = true
	}

	// this is the 'default' behavior when no command line arguments are given
	// if no argv was set, select repos marked as 'mine'
	if !done {
		findMine()
		done = true
	}
	return done
}

func findPrivate() {
	repos := me.forge.Repos.SortByGoPath()
	for repos.Scan() {
		repo := repos.Next()
		if me.forge.Config.IsPrivate(repo.GoPath) {
			me.found.AppendUniqueGoPath(repo)
		}
	}
}

// finds repos that are writable
func findMine() {
	// log.Printf("get mine %s\n", me.forge.GetGoSrc())
	repos := me.forge.Repos.SortByGoPath()
	for repos.Scan() {
		repo := repos.Next()
		if me.forge.Config.IsWritable(repo.GoPath) {
			me.found.AppendUniqueGoPath(repo)
		}
	}
}

// finds repos that are writable
func findFavorites() {
	// log.Printf("get favorites %s\n", me.forge.GetGoSrc())
	repos := me.forge.Repos.SortByGoPath()
	for repos.Scan() {
		repo := repos.Next()
		if me.forge.Config.IsFavorite(repo.GoPath) {
			me.found.AppendUniqueGoPath(repo)
		}
	}
}

func findAll() {
	var configsave bool
	repos := me.forge.Repos.SortByGoPath()
	for repos.Scan() {
		repo := repos.Next()
		if me.forge.Config.IsReadOnly(repo.GoPath) && !argv.FindReadOnly {
			if repo.ReadOnly {
				continue
			}
			log.Info("todo: ConfigSave() readonly flag on repo is wrong", repo.GoPath)
			repo.ReadOnly = true
			configsave = true
			continue
		}
		me.found.AppendUniqueGoPath(repo)
	}
	if configsave {
		log.Info("should ConfigSave here")
		me.forge.Repos.ConfigSave()
	}
}