From b3bca658f57ca3c4f0b44318f486b5ac1e10b03c Mon Sep 17 00:00:00 2001 From: Michal Gorecki Date: Wed, 5 Mar 2025 11:41:49 +0100 Subject: [PATCH] newt: Add flag to print external repos info Now it's possible to print also external repos info with newt info command. To do so use -e --external flag --- newt/cli/project_cmds.go | 10 ++++++---- newt/install/install.go | 1 - newt/project/project.go | 32 +++++++++++++++++++++++++++----- 3 files changed, 33 insertions(+), 10 deletions(-) diff --git a/newt/cli/project_cmds.go b/newt/cli/project_cmds.go index a14f796b77..dffe51572a 100644 --- a/newt/cli/project_cmds.go +++ b/newt/cli/project_cmds.go @@ -34,6 +34,7 @@ import ( ) var infoRemote bool +var infoExternal bool func newRunCmd(cmd *cobra.Command, args []string) { if len(args) < 1 { @@ -148,11 +149,9 @@ func infoRunCmd(cmd *cobra.Command, args []string) { // If no arguments specified, print status of all installed repos. if len(args) == 0 { - pred := func(r *repo.Repo) bool { return true } - if err := proj.InfoIf(pred, infoRemote); err != nil { + if err := proj.Info(infoRemote, infoExternal); err != nil { NewtUsage(nil, err) } - return } @@ -243,7 +242,10 @@ func AddProjectCommands(cmd *cobra.Command) { } infoCmd.PersistentFlags().BoolVarP(&infoRemote, "remote", "r", false, - "Fetch latest repos to determine if upgrades are required") + "Fetch latest repos to determine if upgrades are required. Works only on internal repositories.") + infoCmd.PersistentFlags().BoolVarP(&infoExternal, + "external", "e", false, + "Include external repositories.") cmd.AddCommand(infoCmd) } diff --git a/newt/install/install.go b/newt/install/install.go index 36faf4fde9..c162498d05 100644 --- a/newt/install/install.go +++ b/newt/install/install.go @@ -679,7 +679,6 @@ func (inst *Installer) Info(repos []*repo.Repo, remote bool) error { vmp = &vm } - util.StatusMessage(util.VERBOSITY_DEFAULT, "Repository info:\n") for _, r := range repos { if r.IsLocal() { inst.localRepoInfo(r) diff --git a/newt/project/project.go b/newt/project/project.go index 48ac577421..382e915cb4 100644 --- a/newt/project/project.go +++ b/newt/project/project.go @@ -411,9 +411,7 @@ func (proj *Project) UpgradeIf( return inst.Upgrade(specifiedRepoList, force, ask) } -func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool, - remote bool) error { - +func (proj *Project) Info(remote bool, external bool) error { if remote { // Make sure we have an up to date copy of all `repository.yml` files. if err := proj.downloadRepositoryYmlFiles(); err != nil { @@ -422,15 +420,39 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool, } // Determine which repos the user wants info about. - repoList := proj.SelectRepos(predicate) + predicate := func(r *repo.Repo) bool { return true } + internalRepos := proj.SelectRepos(predicate) + + if !remote && external { + proj.GetPkgRepos() + } + + predicate = func(r *repo.Repo) bool { + for _, intRepo := range internalRepos { + if intRepo.Name() == r.Name() { + return false + } + } + return true + } + // This should be empty slice if remote is true + externalRepos := proj.SelectRepos(predicate) // Ignore errors. We will deal with bad repos individually when we display // info about them. inst, _ := install.NewInstaller(proj.repos, proj.rootRepoReqs) - if err := inst.Info(repoList, remote); err != nil { + util.StatusMessage(util.VERBOSITY_DEFAULT, "Internal repository info:\n") + if err := inst.Info(internalRepos, remote); err != nil { return err } + if !remote && external { + util.StatusMessage(util.VERBOSITY_DEFAULT, "External repository info:\n") + if err := inst.Info(externalRepos, remote); err != nil { + return err + } + } + return nil }