gogenlicense

command
v1.2.7 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 21, 2024 License: MIT Imports: 11 Imported by: 0

Documentation

Overview

Command gogenlicense finds and formats package licenses for use in go programs. It is intended to comply with license requirements, but has not been vetted by a lawyer.

Concretely this package generates go code that contains a single string variable which includes all legal notices. It also generates appropriate comments for godoc.

Quickstart

gogenlicense is most commonly invoked using a 'go:generate' comment like so:

//go:generate gogenlicense -m

After adding such a comment, run the 'go generate' command. Once a source file has been generated, your go code can make use of the generated notices. For example to add a legal flag that prints notices:

var legalFlag bool
flag.BoolVar(&legalFlag, "legal", legalFlag, "print legal notices and exit")
defer func() {
	if legalFlag {
		fmt.Println("This executable contains code from several different go packages. ")
		fmt.Println("Some of these packages require licensing information to be made available to the end user. ")
		fmt.Println(legal.Notices) // this references the generated constant!
		os.Exit(0)
	}
}()

For a more complete example, see the source code of this command. The notices constant is implemented in the github.com/tkw1536/gogenlicense/legal subpackage. The legal flag is implemented in the main package.

For usage of the go generate command, see https://golang.org/pkg/cmd/go/internal/generate/.

Usage

The full invocation of the command is as follows:

gogenlicense [-legal] [-help] [-o FILE] [-t THRESHOLD] [-p PACKAGE] [-n NAME] [-m] [MODULE [MODULE...]]
-legal
  Print legal notices and exit.
-help
  Print a usage message and exit.
-p PACKAGE
  Package name of go source code file to generate.
  Defaults to the 'GOPACKAGE' environment variable, or to 'notices' if unset.
-n string
  Name of declaration to generate (default 'Notices')
-t THRESHOLD
 Threshold to use for the license classifier, between 0 and 1.
 Defaults to 0.9.
-o filename
  Path to write output to.
  Defaults to appending a suffix '_notices' to the source file pointed to by the 'GOFILE' environment variable.
  If 'GOFILE' is not provided, uses the filename 'notices.go'.
MODULE
  Import path of module to scan for module dependencies.
-m
  automatically find the current 'go module' containing the working directory and include it in MODULE list.

Acknowledgements

This command was inspired by the https://classic.yarnpkg.com/lang/en/docs/cli/licenses/#toc-yarn-licenses-generate-disclaimer command. Internally this command relies on the excellent https://github.com/google/go-licenses package. See also the legal subpackage for full licenses of used packages.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL