github.com/ActiveState/cli@v0.0.0-20240508170324-6801f60cd051/internal/runbits/dependencies/summary.go (about)

     1  package dependencies
     2  
     3  import (
     4  	"fmt"
     5  	"sort"
     6  	"strconv"
     7  
     8  	"github.com/ActiveState/cli/internal/locale"
     9  	"github.com/ActiveState/cli/internal/output"
    10  	"github.com/ActiveState/cli/pkg/buildplan"
    11  )
    12  
    13  // OutputSummary lists the given runtime dependencies being installed along with their
    14  // subdependencies (if any).
    15  func OutputSummary(out output.Outputer, directDependencies buildplan.Artifacts) {
    16  	if len(directDependencies) == 0 {
    17  		return
    18  	}
    19  
    20  	ingredients := directDependencies.Filter(buildplan.FilterStateArtifacts()).Ingredients()
    21  
    22  	sort.SliceStable(ingredients, func(i, j int) bool {
    23  		return ingredients[i].Name < ingredients[j].Name
    24  	})
    25  
    26  	out.Notice("") // blank line
    27  
    28  	out.Notice(locale.Tl("setting_up_dependencies", "Setting up the following dependencies:"))
    29  
    30  	for i, ingredient := range ingredients {
    31  		prefix := "├─"
    32  		if i == len(ingredients)-1 {
    33  			prefix = "└─"
    34  		}
    35  
    36  		subdependencies := ""
    37  		if numSubs := len(ingredient.RuntimeDependencies(true)); numSubs > 0 {
    38  			subdependencies = locale.Tl("summary_subdeps", "([ACTIONABLE]{{.V0}}[/RESET] sub-dependencies)", strconv.Itoa(numSubs))
    39  		}
    40  
    41  		item := fmt.Sprintf("[ACTIONABLE]%s@%s[/RESET] %s", ingredient.Name, ingredient.Version, subdependencies)
    42  
    43  		out.Notice(fmt.Sprintf("[DISABLED]%s[/RESET] %s", prefix, item))
    44  	}
    45  
    46  	out.Notice("") // blank line
    47  }