mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-01-11 03:11:50 +00:00
Raw (machine-readable) format for aptly mirror/repo/snapshot list. #27
This commit is contained in:
@@ -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
|
||||
}
|
||||
|
||||
@@ -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
|
||||
}
|
||||
|
||||
@@ -14,26 +14,39 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error {
|
||||
return err
|
||||
}
|
||||
|
||||
if context.CollectionFactory().SnapshotCollection().Len() > 0 {
|
||||
fmt.Printf("List of snapshots:\n")
|
||||
raw := cmd.Flag.Lookup("raw").Value.Get().(bool)
|
||||
|
||||
snapshots := make([]string, context.CollectionFactory().SnapshotCollection().Len())
|
||||
snapshots := make([]string, context.CollectionFactory().SnapshotCollection().Len())
|
||||
|
||||
i := 0
|
||||
context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
||||
i := 0
|
||||
context.CollectionFactory().SnapshotCollection().ForEach(func(snapshot *deb.Snapshot) error {
|
||||
if raw {
|
||||
snapshots[i] = snapshot.Name
|
||||
} else {
|
||||
snapshots[i] = snapshot.String()
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
sort.Strings(snapshots)
|
||||
for _, snapshot := range snapshots {
|
||||
fmt.Printf(" * %s\n", snapshot)
|
||||
}
|
||||
i++
|
||||
return nil
|
||||
})
|
||||
|
||||
fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show <name>`.\n")
|
||||
sort.Strings(snapshots)
|
||||
|
||||
if raw {
|
||||
for _, snapshot := range snapshots {
|
||||
fmt.Printf("%s\n", snapshot)
|
||||
}
|
||||
} else {
|
||||
fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n")
|
||||
if len(snapshots) > 0 {
|
||||
fmt.Printf("List of snapshots:\n")
|
||||
|
||||
for _, snapshot := range snapshots {
|
||||
fmt.Printf(" * %s\n", snapshot)
|
||||
}
|
||||
|
||||
fmt.Printf("\nTo get more information about snapshot, run `aptly snapshot show <name>`.\n")
|
||||
} else {
|
||||
fmt.Printf("\nNo snapshots found, create one with `aptly snapshot create...`.\n")
|
||||
}
|
||||
}
|
||||
return err
|
||||
|
||||
@@ -53,5 +66,7 @@ Example:
|
||||
`,
|
||||
}
|
||||
|
||||
cmd.Flag.Bool("raw", false, "display list in machine-readable format")
|
||||
|
||||
return cmd
|
||||
}
|
||||
|
||||
12
system/t04_mirror/ListMirror3Test_gold
Normal file
12
system/t04_mirror/ListMirror3Test_gold
Normal file
@@ -0,0 +1,12 @@
|
||||
gnuplot-maverick
|
||||
gnuplot-maverick-src
|
||||
wheezy-backports
|
||||
wheezy-backports-src
|
||||
wheezy-contrib
|
||||
wheezy-contrib-src
|
||||
wheezy-main
|
||||
wheezy-main-src
|
||||
wheezy-non-free
|
||||
wheezy-non-free-src
|
||||
wheezy-updates
|
||||
wheezy-updates-src
|
||||
0
system/t04_mirror/ListMirror4Test_gold
Normal file
0
system/t04_mirror/ListMirror4Test_gold
Normal file
@@ -19,3 +19,18 @@ class ListMirror2Test(BaseTest):
|
||||
list mirrors: empty list
|
||||
"""
|
||||
runCmd = "aptly mirror list"
|
||||
|
||||
|
||||
class ListMirror3Test(BaseTest):
|
||||
"""
|
||||
list mirrors: raw list
|
||||
"""
|
||||
fixtureDB = True
|
||||
runCmd = "aptly -raw mirror list"
|
||||
|
||||
|
||||
class ListMirror4Test(BaseTest):
|
||||
"""
|
||||
list mirrors: raw empty list
|
||||
"""
|
||||
runCmd = "aptly -raw mirror list"
|
||||
|
||||
5
system/t05_snapshot/ListSnapshot3Test_gold
Normal file
5
system/t05_snapshot/ListSnapshot3Test_gold
Normal file
@@ -0,0 +1,5 @@
|
||||
snap1
|
||||
snap2
|
||||
snap3
|
||||
snap4
|
||||
snap5
|
||||
0
system/t05_snapshot/ListSnapshot4Test_gold
Normal file
0
system/t05_snapshot/ListSnapshot4Test_gold
Normal file
@@ -23,3 +23,27 @@ class ListSnapshot2Test(BaseTest):
|
||||
list snapshots: empty list
|
||||
"""
|
||||
runCmd = "aptly snapshot list"
|
||||
|
||||
|
||||
class ListSnapshot3Test(BaseTest):
|
||||
"""
|
||||
list snapshots: raw regular list
|
||||
"""
|
||||
fixtureDB = True
|
||||
fixtureCmds = [
|
||||
"aptly snapshot create snap1 from mirror wheezy-main",
|
||||
"aptly snapshot create snap2 from mirror wheezy-contrib",
|
||||
"aptly snapshot merge snap3 snap1 snap2",
|
||||
"aptly snapshot pull snap1 snap2 snap4 mame unrar",
|
||||
"aptly repo create local-repo",
|
||||
"aptly repo add local-repo ${files}",
|
||||
"aptly snapshot create snap5 from repo local-repo",
|
||||
]
|
||||
runCmd = "aptly -raw snapshot list"
|
||||
|
||||
|
||||
class ListSnapshot4Test(BaseTest):
|
||||
"""
|
||||
list snapshots: raw empty list
|
||||
"""
|
||||
runCmd = "aptly snapshot -raw list"
|
||||
|
||||
@@ -1,4 +1,4 @@
|
||||
List of mirrors:
|
||||
List of local repos:
|
||||
* [repo1] (packages: 0)
|
||||
* [repo2]: Cool2 (packages: 0)
|
||||
* [repo3]: Cool3 (packages: 0)
|
||||
|
||||
0
system/t09_repo/ListRepo3Test_gold
Normal file
0
system/t09_repo/ListRepo3Test_gold
Normal file
3
system/t09_repo/ListRepo4Test_gold
Normal file
3
system/t09_repo/ListRepo4Test_gold
Normal file
@@ -0,0 +1,3 @@
|
||||
repo1
|
||||
repo2
|
||||
repo3
|
||||
@@ -18,3 +18,22 @@ class ListRepo2Test(BaseTest):
|
||||
"aptly repo create repo1",
|
||||
]
|
||||
runCmd = "aptly repo list"
|
||||
|
||||
|
||||
class ListRepo3Test(BaseTest):
|
||||
"""
|
||||
list local repos: raw no repos
|
||||
"""
|
||||
runCmd = "aptly -raw repo list"
|
||||
|
||||
|
||||
class ListRepo4Test(BaseTest):
|
||||
"""
|
||||
list local repo: raw normal
|
||||
"""
|
||||
fixtureCmds = [
|
||||
"aptly repo create -comment=Cool3 repo3",
|
||||
"aptly repo create -comment=Cool2 repo2",
|
||||
"aptly repo create repo1",
|
||||
]
|
||||
runCmd = "aptly repo list -raw"
|
||||
|
||||
Reference in New Issue
Block a user