Documentation
¶
Overview ¶
Package copyright includes copyright header management utilities
Index ¶
- Constants
- Variables
- type Action
- type Config
- func (c Config) CompanyOrDefault() string
- func (c Config) DebugOrDefault() bool
- func (c Config) ExitFirstOrDefault() bool
- func (c Config) ExtensionNoticeTemplatesOrDefault() map[string]string
- func (c Config) LicenseOrDefault() string
- func (c Config) NoticeBodyTemplateOrDefault() string
- func (c Config) QuietOrDefault() bool
- func (c Config) RestrictionsOrDefault() string
- func (c Config) ShowDiffOrDefault() bool
- func (c Config) VerboseOrDefault() bool
- func (c Config) YearOrDefault() int
- type Copyright
- func (c Copyright) Debugf(format string, args ...interface{})
- func (c Copyright) Errorf(format string, args ...interface{})
- func (c Copyright) GetStderr() io.Writer
- func (c Copyright) GetStdout() io.Writer
- func (c Copyright) Inject(ctx context.Context, root string) error
- func (c Copyright) Remove(ctx context.Context, root string) error
- func (c Copyright) Verbosef(format string, args ...interface{})
- func (c Copyright) Verify(ctx context.Context, root string) error
- func (c Copyright) Walk(ctx context.Context, action Action, root string) error
- type Option
- func OptCompany(company string) Option
- func OptConfig(cfg Config) Option
- func OptDebug(debug bool) Option
- func OptExcludes(excludeGlobs ...string) Option
- func OptExitFirst(exitFirst bool) Option
- func OptIncludeFiles(includeGlobs ...string) Option
- func OptLicense(license string) Option
- func OptNoticeBodyTemplate(noticeBodyTemplate string) Option
- func OptRestrictions(restrictions string) Option
- func OptVerbose(verbose bool) Option
- func OptYear(year int) Option
Constants ¶
const ( ExtensionUnknown = "" ExtensionCSS = ".css" ExtensionGo = ".go" ExtensionHTML = ".html" ExtensionJS = ".js" ExtensionJSX = ".jsx" ExtensionPy = ".py" ExtensionSASS = ".sass" ExtensionSCSS = ".scss" ExtensionTS = ".ts" ExtensionTSX = ".tsx" ExtensionYAML = ".yaml" ExtensionYML = ".yml" ExtensionSQL = ".sql" ExtensionProto = ".proto" )
Extension
const DefaultCompany = "Blend Labs, Inc"
DefaultCompany is the default company to inject into the notice template.
const DefaultImplicitConfigFile = ".copyright-check-exclude-globs"
DefaultImplicitConfigFile is the file name for the default config file the `copyright` command will parse for globs, if present.
const DefaultNoticeBodyTemplate = `Copyright (c) {{ .Year }} - Present. {{ .Company }}. All rights reserved
{{ .Restrictions }}`
DefaultNoticeBodyTemplate is the default notice body template.
const DefaultOpenSourceLicense = "MIT"
DefaultOpenSourceLicense is the default open source license.
const DefaultRestrictionsInternal = "Blend Confidential - Restricted"
DefaultRestrictionsInternal are the default copyright restrictions to inject into the notice template.
const DefaultRestrictionsOpenSource = `Use of this source code is governed by a {{ .License }} license that can be found in the LICENSE file.`
DefaultRestrictionsOpenSource are the default open source restrictions.
Variables ¶
var ( // KnownExtensions is a list of all the known extensions. KnownExtensions = []string{ ExtensionCSS, ExtensionGo, ExtensionHTML, ExtensionJS, ExtensionJSX, ExtensionPy, ExtensionSCSS, ExtensionSASS, ExtensionTS, ExtensionTSX, ExtensionYAML, ExtensionYML, ExtensionSQL, ExtensionProto, } // DefaultExtensionNoticeTemplates is a mapping between file extension (including the prefix dot) to the notice templates. DefaultExtensionNoticeTemplates = map[string]string{ ExtensionCSS: cssNoticeTemplate, ExtensionGo: goNoticeTemplate, ExtensionHTML: htmlNoticeTemplate, ExtensionJS: jsNoticeTemplate, ExtensionJSX: jsNoticeTemplate, ExtensionPy: pythonNoticeTemplate, ExtensionSASS: sassNoticeTemplate, ExtensionSCSS: scssNoticeTemplate, ExtensionTS: tsNoticeTemplate, ExtensionTSX: tsNoticeTemplate, ExtensionYAML: yamlNoticeTemplate, ExtensionYML: yamlNoticeTemplate, ExtensionSQL: sqlNoticeTemplate, ExtensionProto: protoNoticeTemplate, } // DefaultExcludes is the default excluded directories. DefaultExcludes = []string{ ".git/*", ".github/*", "*/_config", "*/_config/*", "*/dist/*", "*/node_modules/*", "*/testdata", "*/testdata/*", "*/vendor/*", "node_modules/*", "protogen/*", "*.pb.go", "vendor/*", "venv/*", "*/venv/*", "*.vault.yml", } // DefaultIncludeFiles is the default included files list. DefaultIncludeFiles = []string{ "*.css", "*.go", "*.html", "*.js", "*.jsx", "*.py", "*.sass", "*.scss", "*.ts", "*.tsx", "*.yaml", "*.yml", "*.sql", "*.proto", } )
var ( ErrWalkSkip = errors.New("walk skip; we should not process this file or path") ErrFailure = errors.New("failure; one or more steps failed") )
Error sentinels
var (
VerifyErrorFormat = "%s: copyright header missing or invalid"
)
Error Strings
Functions ¶
This section is empty.
Types ¶
type Config ¶
type Config struct { // NoticeBodyTemplate is the notice body template that will be processed and // injected to the relevant extension specific notice template. NoticeBodyTemplate string `yaml:"noticeBodyTemplate"` // Year is the year to insert into the templates as `{{ .Year }}` Year int `yaml:"year"` // Company is the company name to insert into the templates as `{{ .Company }}` Company string `yaml:"company"` // License is the open source license to insert into in templates as `{{ .License }}` License string `yaml:"openSourceLicense"` // Restrictions an optional template to clarify copyright restrictions or // visibility modifiers, which is available in the `NoticeBodyTemplate` as `{{ .Restrictions }}` Restrictions string `yaml:"restrictionTemplate"` // Excludes are a list of globs to exclude, they can // match both files and directories. // This can be populated with `.gitignore` and the like. Excludes []string `yaml:"excludes"` // IncludeFiles are a list of globs to match files to include. IncludeFiles []string `yaml:"includeFiles"` // ExtensionNoticeTemplates is a map between file extension (including dot prefix) // to the relevant full notice template for the file. It can include a template variable // {{ .Notice }} that will insert the compiled `NoticyBodyTemplate`. ExtensionNoticeTemplates map[string]string // FallbackNoticeTemplate is a full notice template that will be used if there is no extension // specific notice template. // It can include the template variable {{ .Notice }} that will instert the compiled `NoticeBodyTemplate`. FallbackNoticeTemplate string // ExitFirst indicates if we should return after the first failure. ExitFirst *bool `yaml:"exitFirst"` // Quiet controls whether output is suppressed. Quiet *bool `yaml:"quiet"` // Verbose controls whether verbose output is shown. Verbose *bool `yaml:"verbose"` // Debug controls whether debug output is shown. Debug *bool `yaml:"debug"` // ShowDiff shows shows the diffs on verification failues. ShowDiff *bool `yaml:"verifyDiff"` }
Config holds the runtime configuration option for the copyright engine.
func (Config) CompanyOrDefault ¶
CompanyOrDefault returns a company name or a default.
func (Config) DebugOrDefault ¶
DebugOrDefault returns a value or a default.
func (Config) ExitFirstOrDefault ¶
ExitFirstOrDefault returns a value or a default.
func (Config) ExtensionNoticeTemplatesOrDefault ¶ added in v1.20210227.3
ExtensionNoticeTemplatesOrDefault returns mapping between file extensions (including dot) to the notice templates (i.e. how the template should be fully formatted per file type).
func (Config) LicenseOrDefault ¶ added in v1.20210205.5
LicenseOrDefault returns an open source license or a default.
func (Config) NoticeBodyTemplateOrDefault ¶
NoticeBodyTemplateOrDefault returns the notice body template or a default.
func (Config) QuietOrDefault ¶ added in v1.20210205.5
QuietOrDefault returns a value or a default.
func (Config) RestrictionsOrDefault ¶ added in v1.20210116.4
RestrictionsOrDefault returns restrictions or a default.
func (Config) ShowDiffOrDefault ¶ added in v1.20210603.3
ShowDiffOrDefault returns a value or a default.
func (Config) VerboseOrDefault ¶
VerboseOrDefault returns a value or a default.
func (Config) YearOrDefault ¶
YearOrDefault returns the current year or a default.
type Copyright ¶
type Copyright struct { Config // Config holds the configuration opitons. // Stdout is the writer for Verbose and Debug output. // If it is unset, `os.Stdout` will be used. Stdout io.Writer // Stderr is the writer for Error output. // If it is unset, `os.Stderr` will be used. Stderr io.Writer }
Copyright is the main type that injects, removes and verifies copyright headers.
func (Copyright) Inject ¶
Inject inserts the copyright header in any matching files that don't already have the copyright header.
func (Copyright) Remove ¶
Remove removes the copyright header in any matching files that have the copyright header.
type Option ¶
type Option func(*Copyright)
Option is a function that modifies a config.
func OptCompany ¶ added in v1.20210116.4
OptCompany sets the template company.
func OptExcludes ¶ added in v1.20210708.4
OptExcludes sets the exclude glob filters.
func OptExitFirst ¶
OptExitFirst sets if we should stop after the first failure.
func OptIncludeFiles ¶
OptIncludeFiles sets the include file glob filters.
func OptLicense ¶ added in v1.20210205.5
OptLicense sets the template license.
func OptNoticeBodyTemplate ¶ added in v1.20210116.4
OptNoticeBodyTemplate sets the notice body template.
func OptRestrictions ¶ added in v1.20210116.4
OptRestrictions sets the template restrictions.
func OptVerbose ¶
OptVerbose sets if we should show verbose output.