feat: print star of module
parent
af2cde423d
commit
7927f61d3c
|
@ -3,6 +3,7 @@ package cli
|
|||
import (
|
||||
"log"
|
||||
|
||||
"github.com/google/go-github/v53/github"
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
|
@ -11,7 +12,8 @@ const (
|
|||
)
|
||||
|
||||
type action struct {
|
||||
flags struct {
|
||||
ghClient *github.Client
|
||||
flags struct {
|
||||
depsFile string
|
||||
depsURL string
|
||||
verbose bool
|
||||
|
|
|
@ -0,0 +1,46 @@
|
|||
package cli
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"regexp"
|
||||
|
||||
"github.com/urfave/cli/v2"
|
||||
)
|
||||
|
||||
var reGitHub = regexp.MustCompile(`github\.com/([^/]*)/([^/]*)`)
|
||||
|
||||
func (a *action) Overlook(c *cli.Context) error {
|
||||
a.getFlags(c)
|
||||
|
||||
mapImportedModules, err := a.runGetImportedModules(c)
|
||||
if err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
for module := range mapImportedModules {
|
||||
if !reGitHub.MatchString(module) {
|
||||
continue
|
||||
}
|
||||
|
||||
parts := reGitHub.FindStringSubmatch(module)
|
||||
if len(parts) != 3 {
|
||||
continue
|
||||
}
|
||||
|
||||
owner := parts[1]
|
||||
repo := parts[2]
|
||||
|
||||
ghRepo, _, err := a.ghClient.Repositories.Get(c.Context, owner, repo)
|
||||
if err != nil {
|
||||
a.log("Failed to get GitHub %s/%s: %s\n", owner, repo, err)
|
||||
}
|
||||
|
||||
starCount := 0
|
||||
if ghRepo.StargazersCount != nil {
|
||||
starCount = *ghRepo.StargazersCount
|
||||
}
|
||||
fmt.Printf("Module %s: Star %d\n", module, starCount)
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
|
@ -16,6 +16,9 @@ const (
|
|||
commandRunName = "run"
|
||||
commandRunUsage = "run the program"
|
||||
|
||||
commandOverlookName = "overlook"
|
||||
commandOverlookUsage = "take a quick lock"
|
||||
|
||||
flagVerboseName = "verbose"
|
||||
flagVerboseUsage = "show what is going on"
|
||||
|
||||
|
@ -32,14 +35,15 @@ const (
|
|||
var aliasFlagVerbose = []string{"v"}
|
||||
|
||||
type App struct {
|
||||
cliApp *cli.App
|
||||
ghClient *github.Client
|
||||
cliApp *cli.App
|
||||
}
|
||||
|
||||
func NewApp(
|
||||
ghClient *github.Client,
|
||||
) *App {
|
||||
a := &action{}
|
||||
a := &action{
|
||||
ghClient: ghClient,
|
||||
}
|
||||
|
||||
cliApp := &cli.App{
|
||||
Name: name,
|
||||
|
@ -69,13 +73,24 @@ func NewApp(
|
|||
},
|
||||
Action: a.Run,
|
||||
},
|
||||
{
|
||||
Name: commandOverlookName,
|
||||
Usage: commandOverlookUsage,
|
||||
Flags: []cli.Flag{
|
||||
&cli.BoolFlag{
|
||||
Name: flagVerboseName,
|
||||
Aliases: aliasFlagVerbose,
|
||||
Usage: flagVerboseUsage,
|
||||
},
|
||||
},
|
||||
Action: a.Overlook,
|
||||
},
|
||||
},
|
||||
Action: a.RunHelp,
|
||||
}
|
||||
|
||||
return &App{
|
||||
cliApp: cliApp,
|
||||
ghClient: ghClient,
|
||||
cliApp: cliApp,
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in New Issue