diff --git a/cmd/publish_list.go b/cmd/publish_list.go index 69e5b4c607..d6e6ef2eca 100644 --- a/cmd/publish_list.go +++ b/cmd/publish_list.go @@ -27,7 +27,7 @@ func aptlyPublishList(cmd *commander.Command, args []string) error { if raw { published = append(published, fmt.Sprintf("%s %s", repo.StoragePrefix(), repo.Distribution)) } else { - published = append(published, repo.String()) + published = append(published, repo.StringWithSources(context.CollectionFactory().SnapshotCollection())) } return nil }) diff --git a/cmd/snapshot_list.go b/cmd/snapshot_list.go index 06ba631c37..ad0c939ca6 100644 --- a/cmd/snapshot_list.go +++ b/cmd/snapshot_list.go @@ -28,7 +28,11 @@ func aptlySnapshotList(cmd *commander.Command, args []string) error { fmt.Printf("List of snapshots:\n") err = collection.ForEachSorted(sortMethodString, func(snapshot *deb.Snapshot) error { - fmt.Printf(" * %s\n", snapshot.String()) + descr, err := snapshot.DescriptionWithSources(collection) + if err != nil { + return err + } + fmt.Printf(" * [%s]: %s\n", snapshot.Name, descr) return nil }) diff --git a/cmd/snapshot_show.go b/cmd/snapshot_show.go index 6e275e0e20..421b1432d8 100644 --- a/cmd/snapshot_show.go +++ b/cmd/snapshot_show.go @@ -15,19 +15,25 @@ func aptlySnapshotShow(cmd *commander.Command, args []string) error { name := args[0] - snapshot, err := context.CollectionFactory().SnapshotCollection().ByName(name) + collection := context.CollectionFactory().SnapshotCollection() + + snapshot, err := collection.ByName(name) if err != nil { return fmt.Errorf("unable to show: %s", err) } - err = context.CollectionFactory().SnapshotCollection().LoadComplete(snapshot) + err = collection.LoadComplete(snapshot) + if err != nil { + return fmt.Errorf("unable to show: %s", err) + } + descr, err := snapshot.DescriptionWithSources(collection) if err != nil { return fmt.Errorf("unable to show: %s", err) } fmt.Printf("Name: %s\n", snapshot.Name) fmt.Printf("Created At: %s\n", snapshot.CreatedAt.Format("2006-01-02 15:04:05 MST")) - fmt.Printf("Description: %s\n", snapshot.Description) + fmt.Printf("Description: %s\n", descr) fmt.Printf("Number of packages: %d\n", snapshot.NumPackages()) withPackages := context.Flags().Lookup("with-packages").Value.Get().(bool) diff --git a/deb/publish.go b/deb/publish.go index 98deb4c528..7f12ac5c7e 100644 --- a/deb/publish.go +++ b/deb/publish.go @@ -334,6 +334,51 @@ func (p *PublishedRepo) String() string { strings.Join(sources, ", ")) } +// String returns human-readable representation of PublishedRepo, with current source snapshot names +func (p *PublishedRepo) StringWithSources(collection *SnapshotCollection) string { + var sources = []string{} + + for _, component := range p.Components() { + var source string + + item := p.sourceItems[component] + if item.snapshot != nil { + sourceDesc, err := item.snapshot.DescriptionWithSources(collection) + if err != nil { + // Fallback + source = item.snapshot.String() + } + source = fmt.Sprintf("[%s]: %s", item.snapshot.Name, sourceDesc) + } else if item.localRepo != nil { + source = item.localRepo.String() + } else { + panic("no snapshot/localRepo") + } + + sources = append(sources, fmt.Sprintf("{%s: %s}", component, source)) + } + + var extra string + + if p.Origin != "" { + extra += fmt.Sprintf("origin: %s", p.Origin) + } + + if p.Label != "" { + if extra != "" { + extra += ", " + } + extra += fmt.Sprintf("label: %s", p.Label) + } + + if extra != "" { + extra = " (" + extra + ")" + } + + return fmt.Sprintf("%s/%s%s [%s] publishes %s", p.StoragePrefix(), p.Distribution, extra, strings.Join(p.Architectures, ", "), + strings.Join(sources, ", ")) +} + // StoragePrefix returns combined storage & prefix for the repo func (p *PublishedRepo) StoragePrefix() string { result := p.Prefix diff --git a/deb/snapshot.go b/deb/snapshot.go index f366e00e2b..102df4fdae 100644 --- a/deb/snapshot.go +++ b/deb/snapshot.go @@ -95,6 +95,23 @@ func (s *Snapshot) String() string { return fmt.Sprintf("[%s]: %s", s.Name, s.Description) } +// String returns description of snapshot, with current source names +func (s *Snapshot) DescriptionWithSources(collection *SnapshotCollection) (string, error) { + if s.SourceKind == "snapshot" { + sourceDescription := make([]string, len(s.SourceIDs)) + for i, s := range s.SourceIDs { + source, err := collection.ByUUID(s) + if err != nil { + return "", err + } + sourceDescription[i] = fmt.Sprintf("'%s'", source.Name) + } + return fmt.Sprintf("Merged from sources: %s", strings.Join(sourceDescription, ", ")), nil + } else { + return s.Description, nil + } +} + // NumPackages returns number of packages in snapshot func (s *Snapshot) NumPackages() int { return s.packageRefs.Len()