Skip to content

Commit

Permalink
Add license details output
Browse files Browse the repository at this point in the history
  • Loading branch information
jimschubert committed Oct 23, 2020
1 parent ee4943a commit 62293ad
Show file tree
Hide file tree
Showing 5 changed files with 130 additions and 2 deletions.
77 changes: 77 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,83 @@ This project aims to go one step further and include templating and configuratio
* `CONTRIBUTING.md`
* GitHub Issues and Pull Request templates

## Examples

### Licenses

#### Find licenses by keyword

License keywords

* copyleft
* discouraged
* international
* miscellaneous
* non-reusable
* obsolete
* osi-approved
* permissive
* popular
* redundant
* retired
* special-purpose

Example:

```shell script
ossify license --keyword popular
Apache-2.0 (Apache License, Version 2.0)
BSD-2 (BSD 2-Clause License)
BSD-3 (BSD 3-Clause License)
CDDL-1.0 (Common Development and Distribution License, Version 1.0)
EPL-1.0 (Eclipse Public License, Version 1.0)
GPL-2.0 (GNU General Public License, Version 2.0)
GPL-3.0 (GNU General Public License, Version 3.0)
LGPL-2.1 (GNU Lesser General Public License, Version 2.1)
LGPL-3.0 (GNU Lesser General Public License, Version 3.0)
MIT (MIT/Expat License)
MPL-2.0 (Mozilla Public License, Version 2.0)
```

#### Write out license text to file

```shell script
ossify license MIT > LICENSE
# or, with --id switch. Both are case-insensitive.
ossify license --id mit > LICENSE
```

#### Search for specific license text

```shell script
ossify license --search apache
Apache-1.1 (Apache Software License, Version 1.1)
Apache-2.0 (Apache License, Version 2.0)
```

#### View details for specific license

```shell script
ossify license MIT --details
MIT (MIT/Expat License)
osi-approved, popular, permissive

Common names
* MIT
* Expat

License Standards
* DEP5 MIT
* DEP5 Expat
* SPDX MIT
* Trove License :: OSI Approved :: MIT License

Links
* https://opensource.org/licenses/mit (OSI Page)
* https://tldrlegal.com/license/mit-license (tl;dr legal)
* https://en.wikipedia.org/wiki/MIT_License (Wikipedia page)
```

## License

This project is [Licensed MIT](./LICENSE)
Expand Down
2 changes: 1 addition & 1 deletion cmd/license.go
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,7 @@ var licenseCmd = &cobra.Command{
details := licenseFlags.details
if license != nil {
if details {
_ = license.Print()
_ = license.PrintDetails()
} else {
err := licenses.PrintLicenseText(license.Id, conf.LicensePath)
failOnError(err)
Expand Down
1 change: 1 addition & 0 deletions go.mod
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,7 @@ module github.com/jimschubert/ossify
go 1.14

require (
github.com/fatih/color v1.7.0
github.com/gobuffalo/envy v1.9.0 // indirect
github.com/gobuffalo/packd v1.0.0 // indirect
github.com/gobuffalo/packr v1.30.1
Expand Down
3 changes: 3 additions & 0 deletions go.sum
Original file line number Diff line number Diff line change
Expand Up @@ -41,6 +41,7 @@ github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c
github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38=
github.com/dgrijalva/jwt-go v3.2.0+incompatible/go.mod h1:E3ru+11k8xSBh+hMPgOLZmtrrCbhqsmaPHjLKYnJCaQ=
github.com/dgryski/go-sip13 v0.0.0-20181026042036-e10d5fee7954/go.mod h1:vAd38F8PWV+bWy6jNmig1y/TA+kYO4g3RSRF0IAv0no=
github.com/fatih/color v1.7.0 h1:DkWD4oS2D8LGGgTQ6IvwJJXSL5Vp2ffcQg58nFV38Ys=
github.com/fatih/color v1.7.0/go.mod h1:Zm6kSWBoL9eyXnKyktHP6abPY2pDugNf5KwzbycvMj4=
github.com/fsnotify/fsnotify v1.4.7/go.mod h1:jwhsz4b93w/PPRr/qN1Yymfu8t87LnFCMoQvtojpjFo=
github.com/ghodss/yaml v1.0.0/go.mod h1:4dBDuWmgqj2HViK6kFavaiC9ZROes6MMH2rRYeMEF04=
Expand Down Expand Up @@ -132,7 +133,9 @@ github.com/lithammer/fuzzysearch v1.1.1 h1:8F9OAV2xPuYblToVohjanztdnPjbtA0MLgMvD
github.com/lithammer/fuzzysearch v1.1.1/go.mod h1:H2bng+w5gsR7NlfIJM8ElGZI0sX6C/9uzGqicVXGU6c=
github.com/magiconair/properties v1.8.0/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/magiconair/properties v1.8.1/go.mod h1:PppfXfuXeibc/6YijjN8zIbojt8czPbwD3XqdrwzmxQ=
github.com/mattn/go-colorable v0.0.9 h1:UVL0vNpWh04HeJXV0KLcaT7r06gOH2l4OW6ddYRUIY4=
github.com/mattn/go-colorable v0.0.9/go.mod h1:9vuHe8Xs5qXnSaW/c/ABM9alt+Vo+STaOChaDxuIBZU=
github.com/mattn/go-isatty v0.0.3 h1:ns/ykhmWi7G9O+8a448SecJU3nSMBXJfqQkl0upE1jI=
github.com/mattn/go-isatty v0.0.3/go.mod h1:M+lRXTBqGeGNdLjl/ufCoiOlB5xdOkqRJdNxMWT7Zi4=
github.com/matttproud/golang_protobuf_extensions v1.0.1/go.mod h1:D8He9yQNgCq6Z5Ld7szi9bcBfOoFv/3dc6xSMkL2PC0=
github.com/miekg/dns v1.0.14/go.mod h1:W1PPwlIAgtquWBMBEV9nkV9Cazfe8ScdGz/Lj7v3Nrg=
Expand Down
49 changes: 48 additions & 1 deletion model/License.go
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import (
"fmt"
"strings"

"github.com/fatih/color"
"github.com/lithammer/fuzzysearch/fuzzy"
)

Expand All @@ -23,7 +24,53 @@ type License struct {
type Licenses []License

func (license License) Print() error {
_, err := fmt.Printf("%-20s(%s)\n", license.Id, license.Name)
d := color.New(color.FgWhite, color.Bold)
_, err := d.Printf("%-20s(%s)\n", license.Id, license.Name)
return err
}

func (license License) PrintDetails() error {
builder := strings.Builder{}

bold := color.New(color.FgWhite, color.Bold)
italic := color.New(color.FgWhite, color.Italic)
warn := color.New(color.FgRed, color.Italic)
builder.WriteString(bold.Sprintf("%-20s(%s)\n", license.Id, license.Name))
if len(license.Keywords) > 0 {
builder.WriteString(italic.Sprint(strings.Join(license.Keywords, ", ")))
builder.WriteString("\n")
}
if license.SupersededBy != nil {
builder.WriteString(warn.Sprintf("This license is superseded by %s\n", *license.SupersededBy))
}

if license.OtherNames != nil && len(*license.OtherNames) > 0 {
builder.WriteString(bold.Sprintln("\nCommon names"))
for _, other := range *license.OtherNames {
builder.WriteString(fmt.Sprintf(" * %s\n", other.Name))
}
}

if len(license.Identifiers) > 0 {
builder.WriteString(bold.Sprintln("\nLicense Standards"))
for _, identifier := range license.Identifiers {
builder.WriteString(fmt.Sprintf(" * %-10s %s\t\n", identifier.Scheme, identifier.Identifier))
}
}

if len(license.Links) > 0 {
builder.WriteString(bold.Sprintln("\nLinks"))
for _, link := range license.Links {
builder.WriteString(" * ")
builder.WriteString(link.Url)
if link.Note != nil {
builder.WriteString(italic.Sprintf(" (%s)", *link.Note))
}
builder.WriteString("\n")
}
}

_, err := fmt.Print(builder.String())
return err
}

Expand Down

0 comments on commit 62293ad

Please sign in to comment.