Raw (machine-readable) format for aptly mirror/repo/snapshot list. #27

This commit is contained in:
Andrey Smirnov
2014-04-15 10:43:36 +04:00
parent ce615facf9
commit 90dd21b270
13 changed files with 167 additions and 43 deletions
+30 -14
View File
@@ -14,30 +14,44 @@ func aptlyRepoList(cmd *commander.Command, args []string) error {
return err
}
if context.CollectionFactory().LocalRepoCollection().Len() > 0 {
fmt.Printf("List of mirrors:\n")
repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len())
i := 0
context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
repos := make([]string, context.CollectionFactory().LocalRepoCollection().Len())
i := 0
context.CollectionFactory().LocalRepoCollection().ForEach(func(repo *deb.LocalRepo) error {
if raw {
repos[i] = repo.Name
} else {
err := context.CollectionFactory().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)
}
i++
return nil
})
fmt.Printf("\nTo get more information about local repository, run `aptly repo show <name>`.\n")
sort.Strings(repos)
if raw {
for _, repo := range repos {
fmt.Printf("%s\n", repo)
}
} else {
fmt.Printf("No local repositories found, create one with `aptly repo create ...`.\n")
if len(repos) > 0 {
fmt.Printf("List of local repos:\n")
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
}
@@ -55,5 +69,7 @@ Example:
`,
}
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
return cmd
}