Skip to content

Commit b3bca65

Browse files
committed
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
1 parent 16449ee commit b3bca65

File tree

3 files changed

+33
-10
lines changed

3 files changed

+33
-10
lines changed

newt/cli/project_cmds.go

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -34,6 +34,7 @@ import (
3434
)
3535

3636
var infoRemote bool
37+
var infoExternal bool
3738

3839
func newRunCmd(cmd *cobra.Command, args []string) {
3940
if len(args) < 1 {
@@ -148,11 +149,9 @@ func infoRunCmd(cmd *cobra.Command, args []string) {
148149

149150
// If no arguments specified, print status of all installed repos.
150151
if len(args) == 0 {
151-
pred := func(r *repo.Repo) bool { return true }
152-
if err := proj.InfoIf(pred, infoRemote); err != nil {
152+
if err := proj.Info(infoRemote, infoExternal); err != nil {
153153
NewtUsage(nil, err)
154154
}
155-
156155
return
157156
}
158157

@@ -243,7 +242,10 @@ func AddProjectCommands(cmd *cobra.Command) {
243242
}
244243
infoCmd.PersistentFlags().BoolVarP(&infoRemote,
245244
"remote", "r", false,
246-
"Fetch latest repos to determine if upgrades are required")
245+
"Fetch latest repos to determine if upgrades are required. Works only on internal repositories.")
246+
infoCmd.PersistentFlags().BoolVarP(&infoExternal,
247+
"external", "e", false,
248+
"Include external repositories.")
247249

248250
cmd.AddCommand(infoCmd)
249251
}

newt/install/install.go

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -679,7 +679,6 @@ func (inst *Installer) Info(repos []*repo.Repo, remote bool) error {
679679
vmp = &vm
680680
}
681681

682-
util.StatusMessage(util.VERBOSITY_DEFAULT, "Repository info:\n")
683682
for _, r := range repos {
684683
if r.IsLocal() {
685684
inst.localRepoInfo(r)

newt/project/project.go

Lines changed: 27 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -411,9 +411,7 @@ func (proj *Project) UpgradeIf(
411411
return inst.Upgrade(specifiedRepoList, force, ask)
412412
}
413413

414-
func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
415-
remote bool) error {
416-
414+
func (proj *Project) Info(remote bool, external bool) error {
417415
if remote {
418416
// Make sure we have an up to date copy of all `repository.yml` files.
419417
if err := proj.downloadRepositoryYmlFiles(); err != nil {
@@ -422,15 +420,39 @@ func (proj *Project) InfoIf(predicate func(r *repo.Repo) bool,
422420
}
423421

424422
// Determine which repos the user wants info about.
425-
repoList := proj.SelectRepos(predicate)
423+
predicate := func(r *repo.Repo) bool { return true }
424+
internalRepos := proj.SelectRepos(predicate)
425+
426+
if !remote && external {
427+
proj.GetPkgRepos()
428+
}
429+
430+
predicate = func(r *repo.Repo) bool {
431+
for _, intRepo := range internalRepos {
432+
if intRepo.Name() == r.Name() {
433+
return false
434+
}
435+
}
436+
return true
437+
}
438+
// This should be empty slice if remote is true
439+
externalRepos := proj.SelectRepos(predicate)
426440

427441
// Ignore errors. We will deal with bad repos individually when we display
428442
// info about them.
429443
inst, _ := install.NewInstaller(proj.repos, proj.rootRepoReqs)
430-
if err := inst.Info(repoList, remote); err != nil {
444+
util.StatusMessage(util.VERBOSITY_DEFAULT, "Internal repository info:\n")
445+
if err := inst.Info(internalRepos, remote); err != nil {
431446
return err
432447
}
433448

449+
if !remote && external {
450+
util.StatusMessage(util.VERBOSITY_DEFAULT, "External repository info:\n")
451+
if err := inst.Info(externalRepos, remote); err != nil {
452+
return err
453+
}
454+
}
455+
434456
return nil
435457
}
436458

0 commit comments

Comments
 (0)