summaryrefslogtreecommitdiff
path: root/doShow.go
blob: 99b8d59f2fa4cfcf97c7017860808248193c5b1f (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
// Copyright 2017-2025 WIT.COM Inc. All rights reserved.
// Use of this source code is governed by the GPL 3.0

package main

import (
	"errors"

	"go.wit.com/lib/env"
	"go.wit.com/log"
)

func doShow() (string, error) {
	if argv.Show.Dirty != nil {
		s, err := doDirty()
		return s, err
	}

	if argv.Show.Tag != nil {
		doTag()
		return "tags shown", nil
	}

	if argv.Show.ENV != nil {
		footer := env.PrintTable()
		return "Current env: " + footer, nil
	}

	if argv.Show.Mtime != nil {
		s, err := me.forge.Repos.ScanAllMtimesVerbose()
		return s, err
	}

	if argv.Show.Repo != "" {
		r := me.forge.Repos.FindByNamespace(argv.Show.Repo)
		if r == nil {
			return "no repo " + argv.Show.Repo, errors.New("no repo " + argv.Show.Repo)
		}
		for _, rmote := range r.Config.Remotes {
			stats, err := r.LoadRemoteRefs(rmote.Name)
			if err != nil {
				// return err
			}
			if env.True("resort") {
				stats.SaveByHash()
				log.Info("stats should have been resorted and saved")
			} else {
				footer := stats.PrintTable()
				log.Info("full remote refs footer:", footer)
			}
		}
		return "remote refs table", nil
	}

	found := findRepos()
	if showUrls() {
		found.SortNamespace()
		footer := found.PrintForgedTable()
		return "repos with patches or unsaved changes: " + footer, nil
	}

	// print out the repos
	footer := found.PrintDefaultTB()
	return footer, nil
}

func showUrls() bool {
	if argv.Show == nil {
		return false
	}
	if argv.Show.Repos == nil {
		return false
	}
	if argv.Show.Repos.Urls != nil {
		return true
	}
	return false
}