Skip to content

Instantly share code, notes, and snippets.

@utisam
Last active July 13, 2019 07:58
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save utisam/01455868e1922d0ce73324ed3df85a4b to your computer and use it in GitHub Desktop.
Save utisam/01455868e1922d0ce73324ed3df85a4b to your computer and use it in GitHub Desktop.
credits.sh
#!/bin/bash
cd $(dirname $0)
render_source() {
local -r generator=./$(basename $1)
local -r package=$2
local -r project_root=$3
cat <<EOS
// Code generated by ${generator}. DO NOT EDIT.
// go:generate ${generator}
package ${package}
import "bytes"
var creditsJSON = bytes.TrimSpace([]byte(\`
EOS
gocredits -json ${project_root} | jq -c '{licenses: .Licenses | del(.[].FilePath) | map(with_entries(.key |= ascii_downcase))}'
echo '`))'
}
render_source $0 PACKAGE_NAME PROJECT_ROOT > credits.go
@utisam
Copy link
Author

utisam commented Jul 13, 2019

使いたいパッケージのディレクトリに PACKAGE_NAMEPROJECT_ROOT 適当に設定して保存。初回のみ ./credits.sh を実行。その後は go generate

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment