Skip to content

Commit

Permalink
Merge pull request ribice#32 from ribice/logging
Browse files Browse the repository at this point in the history
Add logging if -v (verbose) flag is provided)
  • Loading branch information
ribice authored Jun 28, 2022
2 parents f1a5060 + 16fd017 commit 2dd9314
Show file tree
Hide file tree
Showing 5 changed files with 14 additions and 2 deletions.
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ builds:
- -s -w
env:
- CGO_ENABLED=0
main: ./cmd/glice.go
main: ./cmd/glice/main.go

archives:
- replacements:
Expand Down
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -55,6 +55,7 @@ All flags are optional. Glice supports the following flags:
- i [boolean, indirect] // Parses indirect dependencies as well
- p [string - path] // Path to be scanned in form of github.com/author/repo
- t [boolean - thanks] // if GitHub API key is provided, setting this flag will star all GitHub repos from dependency. __In order to do this, API key must have access to public_repo__
- v (boolean - verbose) // If enabled, will log dependencies before fetching and printing them.
```

Expand Down
2 changes: 1 addition & 1 deletion api.go
Original file line number Diff line number Diff line change
Expand Up @@ -40,7 +40,7 @@ type Repository struct {
func newGitClient(c context.Context, keys map[string]string, star bool) *gitClient {
var tc *http.Client
var ghLogged bool
if v, _ := keys["github.com"]; v != "" {
if v := keys["github.com"]; v != "" {
ts := oauth2.StaticTokenSource(
&oauth2.Token{AccessToken: v},
)
Expand Down
7 changes: 7 additions & 0 deletions cmd/glice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,6 +2,7 @@ package main

import (
"flag"
"io"
"log"
"os"

Expand All @@ -14,6 +15,7 @@ func main() {
indirect = flag.Bool("i", false, "Gets indirect modules as well")
path = flag.String("p", "", `Path of desired directory to be scanned with Glice (e.g. "github.com/ribice/glice/v2")`)
thx = flag.Bool("t", false, "Stars dependent repos. Needs GITHUB_API_KEY env variable to work")
verbose = flag.Bool("v", false, "Adds verbose logging")
)

flag.Parse()
Expand All @@ -24,6 +26,11 @@ func main() {
*path = cf
}

if !*verbose {
log.SetOutput(io.Discard)
log.SetFlags(0)
}

cl, err := glice.NewClient(*path)
checkErr(err)

Expand Down
4 changes: 4 additions & 0 deletions glice.go
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,7 @@ func NewClient(path string) (*Client, error) {
if !mod.Exists(path) {
return nil, ErrNoGoMod
}

return &Client{path: path}, nil
}

Expand All @@ -49,9 +50,12 @@ func (c *Client) ParseDependencies(includeIndirect, thanks bool) error {
return err
}

log.Printf("Found %d dependencies", len(repos))

ctx := context.Background()
gitCl := newGitClient(ctx, map[string]string{"github.com": githubAPIKey}, thanks)
for _, r := range repos {
log.Printf("Fetching license for: %s", r.URL)
err = gitCl.GetLicense(ctx, r)
if err != nil {
log.Println(err)
Expand Down

0 comments on commit 2dd9314

Please sign in to comment.