From 919dc538148bab74df4a582cbf9e2e3224126383 Mon Sep 17 00:00:00 2001 From: Andrey Smirnov Date: Fri, 7 Feb 2014 13:27:47 +0400 Subject: [PATCH] aptly snapshot create .. empty command --- cmd_snapshot.go | 51 ++++++++++++++++++++++++++++++------------------- 1 file changed, 31 insertions(+), 20 deletions(-) diff --git a/cmd_snapshot.go b/cmd_snapshot.go index cca9e37e..3f22b66b 100644 --- a/cmd_snapshot.go +++ b/cmd_snapshot.go @@ -11,31 +11,42 @@ import ( ) func aptlySnapshotCreate(cmd *commander.Command, args []string) error { - var err error + var ( + err error + snapshot *debian.Snapshot + ) - if len(args) < 4 || args[1] != "from" || args[2] != "mirror" { + if len(args) == 4 && args[1] == "from" && args[2] == "mirror" { + // aptly snapshot create snap from mirror mirror + repoName, snapshotName := args[3], args[0] + + repoCollection := debian.NewRemoteRepoCollection(context.database) + repo, err := repoCollection.ByName(repoName) + if err != nil { + return fmt.Errorf("unable to create snapshot: %s", err) + } + + err = repoCollection.LoadComplete(repo) + if err != nil { + return fmt.Errorf("unable to create snapshot: %s", err) + } + + snapshot, err = debian.NewSnapshotFromRepository(snapshotName, repo) + if err != nil { + return fmt.Errorf("unable to create snapshot: %s", err) + } + } else if len(args) == 2 && args[1] == "empty" { + // aptly snapshot create snap empty + snapshotName := args[0] + + packageList := debian.NewPackageList() + + snapshot = debian.NewSnapshotFromPackageList(snapshotName, nil, packageList, "Created as empty") + } else { cmd.Usage() return err } - repoName, mirrorName := args[3], args[0] - - repoCollection := debian.NewRemoteRepoCollection(context.database) - repo, err := repoCollection.ByName(repoName) - if err != nil { - return fmt.Errorf("unable to create snapshot: %s", err) - } - - err = repoCollection.LoadComplete(repo) - if err != nil { - return fmt.Errorf("unable to create snapshot: %s", err) - } - - snapshot, err := debian.NewSnapshotFromRepository(mirrorName, repo) - if err != nil { - return fmt.Errorf("unable to create snapshot: %s", err) - } - snapshotCollection := debian.NewSnapshotCollection(context.database) err = snapshotCollection.Add(snapshot)