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
+29 -14
View File
@@ -14,24 +14,37 @@ func aptlyMirrorList(cmd *commander.Command, args []string) error {
return err
}
if context.CollectionFactory().RemoteRepoCollection().Len() > 0 {
fmt.Printf("List of mirrors:\n")
repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len())
i := 0
context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
repos := make([]string, context.CollectionFactory().RemoteRepoCollection().Len())
i := 0
context.CollectionFactory().RemoteRepoCollection().ForEach(func(repo *deb.RemoteRepo) error {
if raw {
repos[i] = repo.Name
} else {
repos[i] = repo.String()
i++
return nil
})
sort.Strings(repos)
for _, repo := range repos {
fmt.Printf(" * %s\n", repo)
}
i++
return nil
})
fmt.Printf("\nTo get more information about mirror, run `aptly mirror show <name>`.\n")
sort.Strings(repos)
if raw {
for _, repo := range repos {
fmt.Printf("%s\n", repo)
}
} else {
fmt.Printf("No mirrors found, create one with `aptly mirror create ...`.\n")
if len(repos) > 0 {
fmt.Printf("List of mirrors:\n")
for _, repo := range repos {
fmt.Printf(" * %s\n", repo)
}
fmt.Printf("\nTo get more information about mirror, run `aptly mirror show <name>`.\n")
} else {
fmt.Printf("No mirrors found, create one with `aptly mirror create ...`.\n")
}
}
return err
}
@@ -50,5 +63,7 @@ Example:
`,
}
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
return cmd
}