total match count in title

This commit is contained in:
UmairShahzad 2020-02-20 01:54:51 +05:00
parent 94ef4bb377
commit bb0fe46db6
7 changed files with 78 additions and 63 deletions

View file

@ -5,7 +5,10 @@ import (
"fmt"
"time"
"github.com/cli/cli/internal/ghrepo"
"github.com/cli/cli/pkg/browser"
"github.com/spf13/cobra"
"github.com/spf13/pflag"
md "github.com/vilmibm/go-termd"
)
@ -77,3 +80,37 @@ func FuzzyAgo(ago time.Duration) string {
return fmtDuration(int(ago.Hours()/24/365), "year")
}
func GetTitle(cmd *cobra.Command, cmdType string, limit int, matchCount int, baseRepo *ghrepo.Interface) string {
userSetFlagCounter := 0
limitSet := false
cmd.Flags().Visit(func(f *pflag.Flag) {
userSetFlagCounter += 1
if f.Name == "limit" {
limitSet = true
}
})
title := "\n%s in %s\n\n"
if matchCount == 0 {
msg := fmt.Sprintf("There are no open %ss", cmdType)
if userSetFlagCounter > 0 {
msg = fmt.Sprintf("No %ss match your search", cmdType)
}
return fmt.Sprintf(title, msg, ghrepo.FullName(*baseRepo))
}
if (!limitSet && userSetFlagCounter > 0) || (userSetFlagCounter > 1) {
title = "\n%s match your search in %s\n\n"
}
out := fmt.Sprintf(title, Pluralize(matchCount, cmdType), ghrepo.FullName(*baseRepo))
if limit < matchCount {
out = out + fmt.Sprintln(Gray(fmt.Sprintf("Showing %d/%d results\n", limit, matchCount)))
}
return out
}