2024-12-27 05:34:15 +01:00
|
|
|
package main
|
|
|
|
|
|
|
|
import (
|
|
|
|
"flag"
|
|
|
|
"fmt"
|
|
|
|
"os"
|
|
|
|
)
|
|
|
|
|
|
|
|
func main() {
|
|
|
|
OutputFile := flag.String("output", "LICENSE", "Specify different output file")
|
2024-12-29 05:33:32 +01:00
|
|
|
LicenseID := flag.String("license", "", "Specify license by SPDX ID (e.g. BSD-3-Clause)")
|
2024-12-28 21:16:00 +01:00
|
|
|
AuthorName := flag.String("name", "", "Set the author name (read from Git by default)")
|
|
|
|
AuthorEmail := flag.String("email", "", "Set the author email (read from Git by default)")
|
2024-12-28 20:56:07 +01:00
|
|
|
ListLicenses := flag.Bool("list", false, "List available licenses")
|
2024-12-27 05:34:15 +01:00
|
|
|
flag.Parse()
|
|
|
|
|
2024-12-28 20:56:07 +01:00
|
|
|
if *ListLicenses {
|
|
|
|
listLicenses()
|
2024-12-27 05:34:15 +01:00
|
|
|
os.Exit(0)
|
|
|
|
}
|
|
|
|
|
2024-12-29 05:33:32 +01:00
|
|
|
if *LicenseID == "" {
|
2024-12-27 05:34:15 +01:00
|
|
|
fmt.Printf("Error: No license specified\n\nUse --license LICENSE\n\nAvailable licenses:\n")
|
2024-12-28 20:56:07 +01:00
|
|
|
listLicenses()
|
2024-12-27 05:34:15 +01:00
|
|
|
os.Exit(1)
|
|
|
|
}
|
|
|
|
|
2024-12-29 05:33:32 +01:00
|
|
|
licenseCtx, err := NewLicenseContext(*AuthorName, *AuthorEmail)
|
|
|
|
if err != nil && err.Error() == "Can't read Git config" {
|
|
|
|
fmt.Printf(
|
|
|
|
"Error: Can't read Git config.\n\nUse --name \"NAME\" and --email EMAIL instead.\n",
|
|
|
|
)
|
|
|
|
os.Exit(3)
|
2024-12-27 05:34:15 +01:00
|
|
|
}
|
|
|
|
|
2024-12-29 05:33:32 +01:00
|
|
|
licenser := Licenser{
|
|
|
|
LicenseID: *LicenseID,
|
|
|
|
LicenseContext: licenseCtx,
|
|
|
|
OutputFile: *OutputFile,
|
2024-12-27 05:34:15 +01:00
|
|
|
}
|
|
|
|
|
2024-12-29 05:33:32 +01:00
|
|
|
err = licenser.Generate()
|
|
|
|
if err != nil && err.Error() == "Not supported license" {
|
|
|
|
fmt.Printf("Error: There is no '%s' license\n\nAvailable licenses:\n", *LicenseID)
|
2024-12-28 21:11:35 +01:00
|
|
|
listLicenses()
|
|
|
|
os.Exit(2)
|
2024-12-27 05:34:15 +01:00
|
|
|
}
|
2024-12-29 05:33:32 +01:00
|
|
|
|
|
|
|
if err = licenser.WriteFile(); err != nil {
|
|
|
|
panic(err)
|
|
|
|
}
|
2024-12-27 05:34:15 +01:00
|
|
|
}
|