forked from aptly-dev/aptly
/
repo_list.go
63 lines (52 loc) · 1.34 KB
/
repo_list.go
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
package cmd
import (
"fmt"
"github.com/gonuts/commander"
"github.com/gonuts/flag"
"github.com/smira/aptly/debian"
"sort"
)
func aptlyRepoList(cmd *commander.Command, args []string) error {
var err error
if len(args) != 0 {
cmd.Usage()
return err
}
localRepoCollection := debian.NewLocalRepoCollection(context.database)
if localRepoCollection.Len() > 0 {
fmt.Printf("List of mirrors:\n")
repos := make([]string, localRepoCollection.Len())
i := 0
localRepoCollection.ForEach(func(repo *debian.LocalRepo) error {
err := localRepoCollection.LoadComplete(repo)
if err != nil {
return err
}
repos[i] = fmt.Sprintf(" * %s (packages: %d)", repo.String(), repo.NumPackages())
i++
return nil
})
sort.Strings(repos)
for _, repo := range repos {
fmt.Println(repo)
}
fmt.Printf("\nTo get more information about local repository, run `aptly repo show <name>`.\n")
} else {
fmt.Printf("No local repositories found, create one with `aptly repo create ...`.\n")
}
return err
}
func makeCmdRepoList() *commander.Command {
cmd := &commander.Command{
Run: aptlyRepoList,
UsageLine: "list",
Short: "list local repositories",
Long: `
List shows full list of local package repositories.
Example:
$ aptly repo list
`,
Flag: *flag.NewFlagSet("aptly-repo-list", flag.ExitOnError),
}
return cmd
}