feat: print star of module
parent
af2cde423d
commit
7927f61d3c
|
@ -3,6 +3,7 @@ package cli
|
||||||
import (
|
import (
|
||||||
"log"
|
"log"
|
||||||
|
|
||||||
|
"github.com/google/go-github/v53/github"
|
||||||
"github.com/urfave/cli/v2"
|
"github.com/urfave/cli/v2"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
@ -11,7 +12,8 @@ const (
|
||||||
)
|
)
|
||||||
|
|
||||||
type action struct {
|
type action struct {
|
||||||
flags struct {
|
ghClient *github.Client
|
||||||
|
flags struct {
|
||||||
depsFile string
|
depsFile string
|
||||||
depsURL string
|
depsURL string
|
||||||
verbose bool
|
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"
|
commandRunName = "run"
|
||||||
commandRunUsage = "run the program"
|
commandRunUsage = "run the program"
|
||||||
|
|
||||||
|
commandOverlookName = "overlook"
|
||||||
|
commandOverlookUsage = "take a quick lock"
|
||||||
|
|
||||||
flagVerboseName = "verbose"
|
flagVerboseName = "verbose"
|
||||||
flagVerboseUsage = "show what is going on"
|
flagVerboseUsage = "show what is going on"
|
||||||
|
|
||||||
|
@ -32,14 +35,15 @@ const (
|
||||||
var aliasFlagVerbose = []string{"v"}
|
var aliasFlagVerbose = []string{"v"}
|
||||||
|
|
||||||
type App struct {
|
type App struct {
|
||||||
cliApp *cli.App
|
cliApp *cli.App
|
||||||
ghClient *github.Client
|
|
||||||
}
|
}
|
||||||
|
|
||||||
func NewApp(
|
func NewApp(
|
||||||
ghClient *github.Client,
|
ghClient *github.Client,
|
||||||
) *App {
|
) *App {
|
||||||
a := &action{}
|
a := &action{
|
||||||
|
ghClient: ghClient,
|
||||||
|
}
|
||||||
|
|
||||||
cliApp := &cli.App{
|
cliApp := &cli.App{
|
||||||
Name: name,
|
Name: name,
|
||||||
|
@ -69,13 +73,24 @@ func NewApp(
|
||||||
},
|
},
|
||||||
Action: a.Run,
|
Action: a.Run,
|
||||||
},
|
},
|
||||||
|
{
|
||||||
|
Name: commandOverlookName,
|
||||||
|
Usage: commandOverlookUsage,
|
||||||
|
Flags: []cli.Flag{
|
||||||
|
&cli.BoolFlag{
|
||||||
|
Name: flagVerboseName,
|
||||||
|
Aliases: aliasFlagVerbose,
|
||||||
|
Usage: flagVerboseUsage,
|
||||||
|
},
|
||||||
|
},
|
||||||
|
Action: a.Overlook,
|
||||||
|
},
|
||||||
},
|
},
|
||||||
Action: a.RunHelp,
|
Action: a.RunHelp,
|
||||||
}
|
}
|
||||||
|
|
||||||
return &App{
|
return &App{
|
||||||
cliApp: cliApp,
|
cliApp: cliApp,
|
||||||
ghClient: ghClient,
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue