(cmd *commander.Command, args []string)
| 8 | ) |
| 9 | |
| 10 | func aptlySnapshotDiff(cmd *commander.Command, args []string) error { |
| 11 | var err error |
| 12 | if len(args) != 2 { |
| 13 | cmd.Usage() |
| 14 | return commander.ErrCommandError |
| 15 | } |
| 16 | |
| 17 | onlyMatching := context.Flags().Lookup("only-matching").Value.Get().(bool) |
| 18 | collectionFactory := context.NewCollectionFactory() |
| 19 | |
| 20 | // Load <name-a> snapshot |
| 21 | snapshotA, err := collectionFactory.SnapshotCollection().ByName(args[0]) |
| 22 | if err != nil { |
| 23 | return fmt.Errorf("unable to load snapshot A: %s", err) |
| 24 | } |
| 25 | |
| 26 | err = collectionFactory.SnapshotCollection().LoadComplete(snapshotA) |
| 27 | if err != nil { |
| 28 | return fmt.Errorf("unable to load snapshot A: %s", err) |
| 29 | } |
| 30 | |
| 31 | // Load <name-b> snapshot |
| 32 | snapshotB, err := collectionFactory.SnapshotCollection().ByName(args[1]) |
| 33 | if err != nil { |
| 34 | return fmt.Errorf("unable to load snapshot B: %s", err) |
| 35 | } |
| 36 | |
| 37 | err = collectionFactory.SnapshotCollection().LoadComplete(snapshotB) |
| 38 | if err != nil { |
| 39 | return fmt.Errorf("unable to load snapshot B: %s", err) |
| 40 | } |
| 41 | |
| 42 | // Calculate diff |
| 43 | diff, err := snapshotA.RefList().Diff(snapshotB.RefList(), collectionFactory.PackageCollection()) |
| 44 | if err != nil { |
| 45 | return fmt.Errorf("unable to calculate diff: %s", err) |
| 46 | } |
| 47 | |
| 48 | if len(diff) == 0 { |
| 49 | context.Progress().Printf("Snapshots are identical.\n") |
| 50 | } else { |
| 51 | context.Progress().Printf(" Arch | Package | Version in A | Version in B\n") |
| 52 | for _, pdiff := range diff { |
| 53 | if onlyMatching && (pdiff.Left == nil || pdiff.Right == nil) { |
| 54 | continue |
| 55 | } |
| 56 | |
| 57 | var verA, verB, pkg, arch, code string |
| 58 | |
| 59 | if pdiff.Left == nil { |
| 60 | verA = "-" |
| 61 | verB = pdiff.Right.Version |
| 62 | pkg = pdiff.Right.Name |
| 63 | arch = pdiff.Right.Architecture |
| 64 | } else { |
| 65 | pkg = pdiff.Left.Name |
| 66 | arch = pdiff.Left.Architecture |
| 67 | verA = pdiff.Left.Version |
nothing calls this directly
no test coverage detected