Skip to content

Commit

Permalink
Implement support for multiple arguments including files #6
Browse files Browse the repository at this point in the history
  • Loading branch information
boyter committed Feb 11, 2018
1 parent 4dd1944 commit f7d2cdf
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 14 deletions.
23 changes: 20 additions & 3 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,9 +1,9 @@
licensechecker (lc)
-------------------
`lc` is a command line tool that recursively iterates over a supplied directory
`lc` is a command line tool that recursively iterates over a supplied directory or file
attempting to identify what software license each file is under using the list
of licenses supplied by the SPDX (Software Package Data Exchange) Project. It will pick up
license files named appropiateld or inline licenses such as the below in source files
license files named appropiately or inline licenses such as the below in source files

`SPDX-License-Identifier: GPL-3.0-only`

Expand Down Expand Up @@ -98,6 +98,23 @@ Or to a SPDX 2.1 file
$lc -f spdx -o spdx_example.spdx --pbl .git,vendor,licenses -dn licensechecker -pn licensechecker .
```

You can specify multiple directories as additional arguments and all results will be merged into a single output

```
$ lc -f tabular ./examples/identifier ./scripts
```

You can also specify files and directories as additional arguments

```
$ lc -f tabular README.md LICENSE ./examples/identifier
Directory File License Confidence Size
README.md NOASSERTION 100.00% 8K
LICENSE GPL-3.0-only 99.68% 34.3K
./examples/identifier LICENSE GPL-3.0+ AND MIT 95.40% 1K
./examples/identifier LICENSE2 MIT AND GPL-3.0+ 99.65% 35K
./examples/identifier has_identifier.py (MIT OR GPL-3.0+) AND GPL-2.0 100.00% 428B
```

### SPDX

Expand All @@ -113,7 +130,7 @@ This SPDX Document is valid.

### Package

Run go build for windows and linux then the following in linux
Run go build for windows and linux then the following in linux, keep in mind need to update the version

```
zip -r9 lc-1.0.0-x86_64-pc-windows.zip lc.exe && zip -r9 lc-1.0.0-x86_64-unknown-linux.zip lc
Expand Down
4 changes: 2 additions & 2 deletions main.go
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ func main() {
app.Name = parsers.ToolName
app.Version = parsers.ToolVersion
app.Usage = "Check directory for licenses and list what license(s) a file is under"
app.UsageText = "lc [global options] [DIRECTORY]"
app.UsageText = "lc [global options] [DIRECTORY|FILE] [DIRECTORY|FILE]"

app.Flags = []cli.Flag{
cli.StringFlag{
Expand Down Expand Up @@ -85,7 +85,7 @@ func main() {
},
}
app.Action = func(c *cli.Context) error {
parsers.DirPath = c.Args().Get(0)
parsers.DirFilePaths = c.Args()
parsers.Process()
return nil
}
Expand Down
25 changes: 16 additions & 9 deletions parsers/guesser.go
Original file line number Diff line number Diff line change
Expand Up @@ -20,13 +20,13 @@ import (

// Shared all over the place
var ToolName = "licensechecker"
var ToolVersion = "1.0.1"
var ToolVersion = "1.0.2"

// Set by user as command line arguments
var confidence = 0.0
var Confidence = ""
var PossibleLicenceFiles = ""
var DirPath = "."
var DirFilePaths = []string{}
var PathBlacklist = ""
var deepGuess = true
var DeepGuess = ""
Expand Down Expand Up @@ -340,16 +340,23 @@ func Process() {

fileResults := []FileResult{}

if DirPath == "" {
DirPath = "."
if len(DirFilePaths) == 0 {
DirFilePaths = append(DirFilePaths, ".")
}

if info, err := os.Stat(DirPath); err == nil && info.IsDir() {
fileResults = walkDirectory(DirPath, [][]LicenseMatch{})
} else {
fmt.Println("Argument " + DirPath + " should be a directory not a file")
}
for _, fileDirectory := range DirFilePaths {
if info, err := os.Stat(fileDirectory); err == nil && info.IsDir() {
fileResults = append(fileResults, walkDirectory(fileDirectory, [][]LicenseMatch{})...)
} else {
directory, file := filepath.Split(fileDirectory)
fileResult := processFile(directory, file, []LicenseMatch{})
fileResults = append(fileResults, fileResult)

if strings.ToLower(Format) == "progress" {
toProgress(directory, file, []LicenseMatch{}, fileResult.LicenseGuesses, fileResult.LicenseIdentified)
}
}
}
s.Stop()

switch strings.ToLower(Format) {
Expand Down

0 comments on commit f7d2cdf

Please sign in to comment.