mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-05-06 22:18:28 +00:00
all: updates for new gonuts/commander API
This commit is contained in:
+32
-26
@@ -5,14 +5,14 @@ import (
|
|||||||
"github.com/gonuts/commander"
|
"github.com/gonuts/commander"
|
||||||
"github.com/gonuts/flag"
|
"github.com/gonuts/flag"
|
||||||
"github.com/smira/aptly/debian"
|
"github.com/smira/aptly/debian"
|
||||||
"log"
|
|
||||||
"strings"
|
"strings"
|
||||||
)
|
)
|
||||||
|
|
||||||
func aptlyMirrorList(cmd *commander.Command, args []string) {
|
func aptlyMirrorList(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
if len(args) != 0 {
|
if len(args) != 0 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("List of mirrors:\n")
|
fmt.Printf("List of mirrors:\n")
|
||||||
@@ -23,12 +23,14 @@ func aptlyMirrorList(cmd *commander.Command, args []string) {
|
|||||||
})
|
})
|
||||||
|
|
||||||
fmt.Printf("\nTo get more information about repository, run `aptly mirror show <name>`.\n")
|
fmt.Printf("\nTo get more information about repository, run `aptly mirror show <name>`.\n")
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func aptlyMirrorCreate(cmd *commander.Command, args []string) {
|
func aptlyMirrorCreate(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
if len(args) < 3 {
|
if len(args) < 3 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
var architectures []string
|
var architectures []string
|
||||||
@@ -39,28 +41,30 @@ func aptlyMirrorCreate(cmd *commander.Command, args []string) {
|
|||||||
|
|
||||||
repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], architectures)
|
repo, err := debian.NewRemoteRepo(args[0], args[1], args[2], args[3:], architectures)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to create mirror: %s", err)
|
return fmt.Errorf("Unable to create mirror: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo.Fetch(context.downloader)
|
err = repo.Fetch(context.downloader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to fetch mirror: %s", err)
|
return fmt.Errorf("Unable to fetch mirror: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||||
|
|
||||||
err = repoCollection.Add(repo)
|
err = repoCollection.Add(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to add mirror: %s", err)
|
return fmt.Errorf("Unable to add mirror: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("\nMirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
|
fmt.Printf("\nMirror %s successfully added.\nYou can run 'aptly mirror update %s' to download repository contents.\n", repo, repo.Name)
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func aptlyMirrorShow(cmd *commander.Command, args []string) {
|
func aptlyMirrorShow(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
@@ -68,12 +72,12 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) {
|
|||||||
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||||
repo, err := repoCollection.ByName(name)
|
repo, err := repoCollection.ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to show: %s", err)
|
return fmt.Errorf("Unable to show: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repoCollection.LoadComplete(repo)
|
err = repoCollection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to show: %s", err)
|
return fmt.Errorf("Unable to show: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
fmt.Printf("Name: %s\n", repo.Name)
|
fmt.Printf("Name: %s\n", repo.Name)
|
||||||
@@ -92,12 +96,14 @@ func aptlyMirrorShow(cmd *commander.Command, args []string) {
|
|||||||
for name, value := range repo.Meta {
|
for name, value := range repo.Meta {
|
||||||
fmt.Printf("%s: %s\n", name, value)
|
fmt.Printf("%s: %s\n", name, value)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func aptlyMirrorUpdate(cmd *commander.Command, args []string) {
|
func aptlyMirrorUpdate(cmd *commander.Command, args []string) error {
|
||||||
|
var err error
|
||||||
if len(args) != 1 {
|
if len(args) != 1 {
|
||||||
cmd.Usage()
|
cmd.Usage()
|
||||||
return
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
name := args[0]
|
name := args[0]
|
||||||
@@ -105,29 +111,29 @@ func aptlyMirrorUpdate(cmd *commander.Command, args []string) {
|
|||||||
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
repoCollection := debian.NewRemoteRepoCollection(context.database)
|
||||||
repo, err := repoCollection.ByName(name)
|
repo, err := repoCollection.ByName(name)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to update: %s", err)
|
return fmt.Errorf("Unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repoCollection.LoadComplete(repo)
|
err = repoCollection.LoadComplete(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to update: %s", err)
|
return fmt.Errorf("Unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo.Fetch(context.downloader)
|
err = repo.Fetch(context.downloader)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to update: %s", err)
|
return fmt.Errorf("Unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repo.Download(context.downloader, context.database, context.packageRepository)
|
err = repo.Download(context.downloader, context.database, context.packageRepository)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to update: %s", err)
|
return fmt.Errorf("Unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
|
||||||
err = repoCollection.Update(repo)
|
err = repoCollection.Update(repo)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("Unable to update: %s", err)
|
return fmt.Errorf("Unable to update: %s", err)
|
||||||
}
|
}
|
||||||
|
return err
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCmdMirrorCreate() *commander.Command {
|
func makeCmdMirrorCreate() *commander.Command {
|
||||||
@@ -201,17 +207,17 @@ ex:
|
|||||||
return cmd
|
return cmd
|
||||||
}
|
}
|
||||||
|
|
||||||
func makeCmdMirror() *commander.Commander {
|
func makeCmdMirror() *commander.Command {
|
||||||
return &commander.Commander{
|
return &commander.Command{
|
||||||
Name: "mirror",
|
UsageLine: "mirror",
|
||||||
Short: "manage mirrors of remote repositories",
|
Short: "manage mirrors of remote repositories",
|
||||||
Commands: []*commander.Command{
|
Subcommands: []*commander.Command{
|
||||||
makeCmdMirrorCreate(),
|
makeCmdMirrorCreate(),
|
||||||
makeCmdMirrorList(),
|
makeCmdMirrorList(),
|
||||||
makeCmdMirrorShow(),
|
makeCmdMirrorShow(),
|
||||||
//makeCmdMirrorDeestroy(),
|
//makeCmdMirrorDeestroy(),
|
||||||
makeCmdMirrorUpdate(),
|
makeCmdMirrorUpdate(),
|
||||||
},
|
},
|
||||||
Flag: flag.NewFlagSet("aptly-mirror", flag.ExitOnError),
|
Flag: *flag.NewFlagSet("aptly-mirror", flag.ExitOnError),
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -10,14 +10,13 @@ import (
|
|||||||
"os"
|
"os"
|
||||||
)
|
)
|
||||||
|
|
||||||
var cmd *commander.Commander
|
var cmd *commander.Command
|
||||||
|
|
||||||
func init() {
|
func init() {
|
||||||
cmd = &commander.Commander{
|
cmd = &commander.Command{
|
||||||
Name: os.Args[0],
|
UsageLine: os.Args[0],
|
||||||
Commands: []*commander.Command{},
|
Flag: *flag.NewFlagSet("aptly", flag.ExitOnError),
|
||||||
Flag: flag.NewFlagSet("aptly", flag.ExitOnError),
|
Subcommands: []*commander.Command{
|
||||||
Commanders: []*commander.Commander{
|
|
||||||
makeCmdMirror(),
|
makeCmdMirror(),
|
||||||
},
|
},
|
||||||
}
|
}
|
||||||
@@ -48,8 +47,7 @@ func main() {
|
|||||||
// TODO:configure pool dir
|
// TODO:configure pool dir
|
||||||
context.packageRepository = debian.NewRepository("/tmp/aptly")
|
context.packageRepository = debian.NewRepository("/tmp/aptly")
|
||||||
|
|
||||||
args := cmd.Flag.Args()
|
err = cmd.Dispatch(os.Args[1:])
|
||||||
err = cmd.Run(args)
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
log.Fatalf("%s", err)
|
log.Fatalf("%s", err)
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user