doc: Add and use LicenseYear

This commit is contained in:
Hajime Hoshi 2016-10-21 00:12:31 +09:00
parent e2fd9b9e7e
commit 3264532004
2 changed files with 17 additions and 6 deletions

View File

@ -27,6 +27,8 @@ import (
"regexp" "regexp"
"strconv" "strconv"
"strings" "strings"
"github.com/hajimehoshi/ebiten/internal"
) )
func execute(command string, args ...string) error { func execute(command string, args ...string) error {
@ -55,12 +57,7 @@ var (
) )
func init() { func init() {
b, err := ioutil.ReadFile("../LICENSE") year, err := internal.LicenseYear()
if err != nil {
panic(err)
}
license := strings.TrimSpace(string(b))
year, err := strconv.Atoi(regexp.MustCompile(`^Copyright (\d+)`).FindStringSubmatch(license)[1])
if err != nil { if err != nil {
panic(err) panic(err)
} }

View File

@ -17,7 +17,9 @@ package internal
import ( import (
"io/ioutil" "io/ioutil"
"path/filepath" "path/filepath"
"regexp"
"runtime" "runtime"
"strconv"
"strings" "strings"
) )
@ -33,3 +35,15 @@ func LicenseComment() (string, error) {
license := "// " + strings.Join(lines[:len(lines)-1], "\n// ") license := "// " + strings.Join(lines[:len(lines)-1], "\n// ")
return license, nil return license, nil
} }
func LicenseYear() (int, error) {
license, err := LicenseComment()
if err != nil {
return 0, err
}
year, err := strconv.Atoi(regexp.MustCompile(`^// Copyright (\d+)`).FindStringSubmatch(license)[1])
if err != nil {
return 0, err
}
return year, nil
}