Skip to content

Allow setting copyright year #115

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
9 changes: 8 additions & 1 deletion cmd/headers.go
Original file line number Diff line number Diff line change
@@ -6,6 +6,7 @@ package cmd
import (
"fmt"
"os"
"strconv"

"github.com/hashicorp/copywrite/addlicense"
"github.com/hashicorp/go-hclog"
@@ -41,6 +42,7 @@ config, see the "copywrite init" command.`,
mapping := map[string]string{
`spdx`: `project.license`,
`copyright-holder`: `project.copyright_holder`,
`copyright-year`: `project.copyright_year`,
}

// update the running config with any command-line flags
@@ -91,8 +93,12 @@ config, see the "copywrite init" command.`,
ignoredPatterns := lo.Union(conf.Project.HeaderIgnore, autoSkippedPatterns)

// Construct the configuration addLicense needs to properly format headers
var yearStr string
if conf.Project.CopyrightYear > 0 {
yearStr = strconv.Itoa(conf.Project.CopyrightYear)
}
licenseData := addlicense.LicenseData{
Year: "", // by default, we don't include a year in copyright statements
Year: yearStr,
Holder: conf.Project.CopyrightHolder,
SPDXID: conf.Project.License,
}
@@ -130,4 +136,5 @@ func init() {
// These flags will get mapped to keys in the the global Config
headersCmd.Flags().StringP("spdx", "s", "", "SPDX-compliant license identifier (e.g., 'MPL-2.0')")
headersCmd.Flags().StringP("copyright-holder", "c", "", "Copyright holder (default \"HashiCorp, Inc.\")")
headersCmd.Flags().IntP("copyright-year", "y", 0, "Copyright year (default: 0 (empty))")
}