mirror of
https://github.com/aptly-dev/aptly.git
synced 2026-04-19 19:28:22 +00:00
Commands mirror/repo/snapshot rename. #63
This commit is contained in:
@@ -54,6 +54,7 @@ func makeCmdMirror() *commander.Command {
|
||||
makeCmdMirrorShow(),
|
||||
makeCmdMirrorDrop(),
|
||||
makeCmdMirrorUpdate(),
|
||||
makeCmdMirrorRename(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
59
cmd/mirror_rename.go
Normal file
59
cmd/mirror_rename.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/smira/aptly/deb"
|
||||
"github.com/smira/commander"
|
||||
)
|
||||
|
||||
func aptlyMirrorRename(cmd *commander.Command, args []string) error {
|
||||
var (
|
||||
err error
|
||||
repo *deb.RemoteRepo
|
||||
)
|
||||
|
||||
if len(args) != 2 {
|
||||
cmd.Usage()
|
||||
return commander.ErrCommandError
|
||||
}
|
||||
|
||||
oldName, newName := args[0], args[1]
|
||||
|
||||
repo, err = context.CollectionFactory().RemoteRepoCollection().ByName(oldName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
_, err = context.CollectionFactory().RemoteRepoCollection().ByName(newName)
|
||||
if err == nil {
|
||||
return fmt.Errorf("unable to rename: mirror %s already exists", newName)
|
||||
}
|
||||
|
||||
repo.Name = newName
|
||||
err = context.CollectionFactory().RemoteRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nMirror %s -> %s has been successfully renamed.\n", oldName, newName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func makeCmdMirrorRename() *commander.Command {
|
||||
cmd := &commander.Command{
|
||||
Run: aptlyMirrorRename,
|
||||
UsageLine: "rename <old-name> <new-name>",
|
||||
Short: "renames mirror",
|
||||
Long: `
|
||||
Command changes name of the mirror.Mirror name should be unique.
|
||||
|
||||
Example:
|
||||
|
||||
$ aptly mirror rename wheezy-min wheezy-main
|
||||
`,
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
||||
}
|
||||
@@ -19,6 +19,7 @@ func makeCmdRepo() *commander.Command {
|
||||
makeCmdRepoMove(),
|
||||
makeCmdRepoRemove(),
|
||||
makeCmdRepoShow(),
|
||||
makeCmdRepoRename(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
59
cmd/repo_rename.go
Normal file
59
cmd/repo_rename.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/smira/aptly/deb"
|
||||
"github.com/smira/commander"
|
||||
)
|
||||
|
||||
func aptlyRepoRename(cmd *commander.Command, args []string) error {
|
||||
var (
|
||||
err error
|
||||
repo *deb.LocalRepo
|
||||
)
|
||||
|
||||
if len(args) != 2 {
|
||||
cmd.Usage()
|
||||
return commander.ErrCommandError
|
||||
}
|
||||
|
||||
oldName, newName := args[0], args[1]
|
||||
|
||||
repo, err = context.CollectionFactory().LocalRepoCollection().ByName(oldName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
_, err = context.CollectionFactory().LocalRepoCollection().ByName(newName)
|
||||
if err == nil {
|
||||
return fmt.Errorf("unable to rename: local repo %s already exists", newName)
|
||||
}
|
||||
|
||||
repo.Name = newName
|
||||
err = context.CollectionFactory().LocalRepoCollection().Update(repo)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nLocal repo %s -> %s has been successfully renamed.\n", oldName, newName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func makeCmdRepoRename() *commander.Command {
|
||||
cmd := &commander.Command{
|
||||
Run: aptlyRepoRename,
|
||||
UsageLine: "rename <old-name> <new-name>",
|
||||
Short: "renames local repository",
|
||||
Long: `
|
||||
Command changes name of the local repo. Local repo name should be unique.
|
||||
|
||||
Example:
|
||||
|
||||
$ aptly repo rename wheezy-min wheezy-main
|
||||
`,
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
||||
}
|
||||
@@ -17,6 +17,7 @@ func makeCmdSnapshot() *commander.Command {
|
||||
makeCmdSnapshotDiff(),
|
||||
makeCmdSnapshotMerge(),
|
||||
makeCmdSnapshotDrop(),
|
||||
makeCmdSnapshotRename(),
|
||||
},
|
||||
}
|
||||
}
|
||||
|
||||
59
cmd/snapshot_rename.go
Normal file
59
cmd/snapshot_rename.go
Normal file
@@ -0,0 +1,59 @@
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"github.com/smira/aptly/deb"
|
||||
"github.com/smira/commander"
|
||||
)
|
||||
|
||||
func aptlySnapshotRename(cmd *commander.Command, args []string) error {
|
||||
var (
|
||||
err error
|
||||
snapshot *deb.Snapshot
|
||||
)
|
||||
|
||||
if len(args) != 2 {
|
||||
cmd.Usage()
|
||||
return commander.ErrCommandError
|
||||
}
|
||||
|
||||
oldName, newName := args[0], args[1]
|
||||
|
||||
snapshot, err = context.CollectionFactory().SnapshotCollection().ByName(oldName)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
_, err = context.CollectionFactory().SnapshotCollection().ByName(newName)
|
||||
if err == nil {
|
||||
return fmt.Errorf("unable to rename: snapshot %s already exists", newName)
|
||||
}
|
||||
|
||||
snapshot.Name = newName
|
||||
err = context.CollectionFactory().SnapshotCollection().Update(snapshot)
|
||||
if err != nil {
|
||||
return fmt.Errorf("unable to rename: %s", err)
|
||||
}
|
||||
|
||||
fmt.Printf("\nSnapshot %s -> %s has been successfully renamed.\n", oldName, newName)
|
||||
|
||||
return err
|
||||
}
|
||||
|
||||
func makeCmdSnapshotRename() *commander.Command {
|
||||
cmd := &commander.Command{
|
||||
Run: aptlySnapshotRename,
|
||||
UsageLine: "rename <old-name> <new-name>",
|
||||
Short: "renames snapshot",
|
||||
Long: `
|
||||
Command changes name of the snapshot. Snapshot name should be unique.
|
||||
|
||||
Example:
|
||||
|
||||
$ aptly snapshot rename wheezy-min wheezy-main
|
||||
`,
|
||||
}
|
||||
|
||||
return cmd
|
||||
|
||||
}
|
||||
@@ -5,6 +5,7 @@ Commands:
|
||||
create create new mirror
|
||||
drop delete mirror
|
||||
list list mirrors
|
||||
rename renames mirror
|
||||
show show details about mirror
|
||||
update update mirror
|
||||
|
||||
|
||||
@@ -5,6 +5,7 @@ Commands:
|
||||
create create new mirror
|
||||
drop delete mirror
|
||||
list list mirrors
|
||||
rename renames mirror
|
||||
show show details about mirror
|
||||
update update mirror
|
||||
|
||||
|
||||
Reference in New Issue
Block a user