Skip to content

Commit

Permalink
Initial commit for v3
Browse files Browse the repository at this point in the history
  • Loading branch information
mikeschinkel committed Oct 17, 2022
1 parent f3705d0 commit c425f38
Show file tree
Hide file tree
Showing 55 changed files with 3,804 additions and 842 deletions.
7 changes: 3 additions & 4 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,7 +1,6 @@
.idea/
licenses/
*
!*.*
!*/
.DS_Store
.idea/*
.idea/**
bin/**
test/log/**
2 changes: 1 addition & 1 deletion .goreleaser.yml
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ builds:
- linux
goarch:
- amd64
- 386
- "386"
ldflags:
- -s -w
env:
Expand Down
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ Download and install glice by executing:
To update:

```bash
go get -u github.com/ribice/glice/v2
go get -u github.com/ribice/glice/v3
```

## Usage
Expand Down
93 changes: 0 additions & 93 deletions api.go

This file was deleted.

96 changes: 0 additions & 96 deletions api_test.go

This file was deleted.

1 change: 1 addition & 0 deletions cmd/glice/README.v2.md
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
# This is the directory where v2 main.go was.
81 changes: 45 additions & 36 deletions cmd/glice/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -2,66 +2,75 @@ package main

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

"github.com/ribice/glice/v2"
"github.com/ribice/glice/v3/pkg"
)

func main() {
var (
fileWrite = flag.Bool("f", false, "Write all licenses to files")
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")
format = flag.String("fmt", "table", "Output format [table | json | csv]")
output = flag.String("o", "stdout", "Output location [stdout | file]")
extension = map[string]string{
"table": "txt",
"json": "json",
"csv": "csv",
}
)
var (
fileWrite = flag.Bool("f", false, "Write all licenses to files")
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/v3")`)
thanks = flag.Bool("t", false, "Stars dependent repos. Needs GITHUB_API_KEY env variable to work")
verbose = flag.Bool("v", false, "Adds verbose logging")
format = flag.String("fmt", "table", "Output format [table | json | csv]")
notext = flag.Bool("notext", false, "Allows ignoring the capture of license text")
output = flag.String("o", "stdout", "Output location [stdout | file]")
)

func initOptions() *glice.Options {
flag.Parse()
o := glice.GetOptions()
o.WriteFile = *fileWrite
o.IncludeIndirect = *indirect
o.SourceDir = *path
//o.GiveThanks = *thanks
o.LogVerbosely = *verbose
o.OutputFormat = *format
o.NoCaptureLicenseText = *notext
o.OutputDestination = *output

if *path == "" {
if o.SourceDir == "" {
cf, err := os.Getwd()
checkErr(err)
*path = cf
o.SourceDir = cf
}

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

cl, err := glice.NewClient(*path, *format, *output)
return o
}

func main() {

o := initOptions()

client := glice.NewClient(o)
cl, err := client, client.Validate()
checkErr(err)

checkErr(cl.ParseDependencies(*indirect, *thx))
//_, err = cl.ParseDependencies(o)
//checkErr(err)

switch *output {
case "stdout":
cl.Print(os.Stdout)
case "file":
fileName := fmt.Sprintf("dependencies.%s", extension[*format])
f, err := os.Create(fileName)
checkErr(err)
cl.Print(f)
f.Close()
}
checkErr(cl.GenerateOutput())

if *fileWrite {
checkErr(cl.WriteLicensesToFile())
}
}

func checkErr(err error) {
if err != nil {
log.Fatal(err)
log.SetOutput(os.Stderr)
if el, ok := err.(glice.ErrorList); ok {
for _, err := range el {
log.Print(err.Error())
}
log.Fatalf("%d errors occured", len(el))
}
log.Fatal(err.Error())

}
}
25 changes: 25 additions & 0 deletions cmd/init.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
package cmd

import (
"github.com/ribice/glice/v3/pkg"
"github.com/spf13/cobra"
)

// initCmd represents the init command
var initCmd = &cobra.Command{
Use: "init",
Run: glice.RunInit,
Short: "Initialize a 'glice.yaml' command in your project's path",
Long: `Initialize a 'glice.yaml' command in your project's path. ` +
`'init' will scan the go.mod file for dependencies and write ` +
`them to the YAML file which can then be hand-edited to add ` +
`overrides. Optionally it can generate a cache-file to allow ` +
`future invocations of the 'scan' command to assume data to ` +
`be current if last scanned within a specifiable TTL (time-to-live.)`,
}

func init() {
rootCmd.AddCommand(initCmd)
initCmd.Flags().String("cache-file", glice.CacheFilepath(), "Full filepath for cache file to create")
initCmd.Flags().String("path", glice.SourceDir(""), "Directory path to your project's top-level go.mod file")
}
36 changes: 36 additions & 0 deletions cmd/print.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
package cmd

import (
"fmt"

"github.com/spf13/cobra"
)

// printCmd represents the print command
var printCmd = &cobra.Command{
Use: "print",
Short: "A brief description of your command",
Long: `A longer description that spans multiple lines and likely contains examples
and usage of using your command. For example:
Cobra is a CLI library for Go that empowers applications.
This application is a tool to generate the needed files
to quickly create a Cobra application.`,
Run: func(cmd *cobra.Command, args []string) {
fmt.Println("print called")
},
}

func init() {
reportCmd.AddCommand(printCmd)

// Here you will define your flags and configuration settings.

// Cobra supports Persistent Flags which will work for this command
// and all subcommands, e.g.:
// printCmd.PersistentFlags().String("foo", "", "A help for foo")

// Cobra supports local flags which will only run when this command
// is called directly, e.g.:
// printCmd.Flags().BoolP("toggle", "t", false, "Help message for toggle")
}
Loading

0 comments on commit c425f38

Please sign in to comment.