Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion cmd/publish_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})
Expand Down
6 changes: 5 additions & 1 deletion cmd/snapshot_list.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
})

Expand Down
12 changes: 9 additions & 3 deletions cmd/snapshot_show.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
45 changes: 45 additions & 0 deletions deb/publish.go
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
17 changes: 17 additions & 0 deletions deb/snapshot.go
Original file line number Diff line number Diff line change
Expand Up @@ -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()
Expand Down