From 9d8e8d03b2e791e6a4a92f3a0fcf094bef578d72 Mon Sep 17 00:00:00 2001 From: Wiktor Zykubek Date: Sun, 29 Dec 2024 16:46:19 +0100 Subject: [PATCH] feat!: rebuild entire cli and reorganize packages --- cmd/add.go | 52 +++++++++++++++++++ cmd/list.go | 23 ++++++++ cmd/root.go | 21 ++++++++ go.mod | 10 +++- go.sum | 9 ++++ git_utils.go => internal/git_utils.go | 2 +- .../license_context.go | 2 +- licenser.go => internal/licenser.go | 4 +- templates.go => internal/templates.go | 15 ++---- {templates => internal/templates}/0BSD.tmpl | 0 .../templates}/AFL-3.0.tmpl | 0 .../templates}/AGPL-3.0.tmpl | 0 .../templates}/Apache-2.0.tmpl | 0 .../templates}/Artistic-2.0.tmpl | 0 .../templates}/BSD-2-Clause-Patent.tmpl | 0 .../templates}/BSD-2-Clause.tmpl | 0 .../templates}/BSD-3-Clause-Clear.tmpl | 0 .../templates}/BSD-3-Clause.tmpl | 0 .../templates}/BSD-4-Clause.tmpl | 0 .../templates}/BSL-1.0.tmpl | 0 .../templates}/BlueOak-1.0.0.tmpl | 0 .../templates}/CC-BY-4.0.tmpl | 0 .../templates}/CC-BY-SA-4.0.tmpl | 0 .../templates}/CC0-1.0.tmpl | 0 .../templates}/CECILL-2.1.tmpl | 0 .../templates}/CERN-OHL-P-2.0.tmpl | 0 .../templates}/CERN-OHL-S-2.0.tmpl | 0 .../templates}/CERN-OHL-W-2.0.tmpl | 0 .../templates}/ECL-2.0.tmpl | 0 .../templates}/EPL-1.0.tmpl | 0 .../templates}/EPL-2.0.tmpl | 0 .../templates}/EUPL-1.1.tmpl | 0 .../templates}/EUPL-1.2.tmpl | 0 .../templates}/GFDL-1.3.tmpl | 0 .../templates}/GPL-2.0.tmpl | 0 .../templates}/GPL-3.0.tmpl | 0 {templates => internal/templates}/ISC.tmpl | 0 .../templates}/LGPL-2.1.tmpl | 0 .../templates}/LGPL-3.0.tmpl | 0 .../templates}/LPPL-1.3c.tmpl | 0 {templates => internal/templates}/MIT-0.tmpl | 0 {templates => internal/templates}/MIT.tmpl | 0 .../templates}/MPL-2.0.tmpl | 0 {templates => internal/templates}/MS-PL.tmpl | 0 {templates => internal/templates}/MS-RL.tmpl | 0 .../templates}/MulanPSL-2.0.tmpl | 0 {templates => internal/templates}/NCSA.tmpl | 0 .../templates}/ODbL-1.0.tmpl | 0 .../templates}/OFL-1.1.tmpl | 0 .../templates}/OSL-3.0.tmpl | 0 .../templates}/PostgreSQL.tmpl | 0 .../templates}/UPL-1.0.tmpl | 0 .../templates}/Unlicense.tmpl | 0 {templates => internal/templates}/Vim.tmpl | 0 {templates => internal/templates}/WTFPL.tmpl | 0 {templates => internal/templates}/Zlib.tmpl | 0 main.go | 47 +---------------- 57 files changed, 125 insertions(+), 60 deletions(-) create mode 100644 cmd/add.go create mode 100644 cmd/list.go create mode 100644 cmd/root.go rename git_utils.go => internal/git_utils.go (94%) rename license_context.go => internal/license_context.go (96%) rename licenser.go => internal/licenser.go (95%) rename templates.go => internal/templates.go (69%) rename {templates => internal/templates}/0BSD.tmpl (100%) rename {templates => internal/templates}/AFL-3.0.tmpl (100%) rename {templates => internal/templates}/AGPL-3.0.tmpl (100%) rename {templates => internal/templates}/Apache-2.0.tmpl (100%) rename {templates => internal/templates}/Artistic-2.0.tmpl (100%) rename {templates => internal/templates}/BSD-2-Clause-Patent.tmpl (100%) rename {templates => internal/templates}/BSD-2-Clause.tmpl (100%) rename {templates => internal/templates}/BSD-3-Clause-Clear.tmpl (100%) rename {templates => internal/templates}/BSD-3-Clause.tmpl (100%) rename {templates => internal/templates}/BSD-4-Clause.tmpl (100%) rename {templates => internal/templates}/BSL-1.0.tmpl (100%) rename {templates => internal/templates}/BlueOak-1.0.0.tmpl (100%) rename {templates => internal/templates}/CC-BY-4.0.tmpl (100%) rename {templates => internal/templates}/CC-BY-SA-4.0.tmpl (100%) rename {templates => internal/templates}/CC0-1.0.tmpl (100%) rename {templates => internal/templates}/CECILL-2.1.tmpl (100%) rename {templates => internal/templates}/CERN-OHL-P-2.0.tmpl (100%) rename {templates => internal/templates}/CERN-OHL-S-2.0.tmpl (100%) rename {templates => internal/templates}/CERN-OHL-W-2.0.tmpl (100%) rename {templates => internal/templates}/ECL-2.0.tmpl (100%) rename {templates => internal/templates}/EPL-1.0.tmpl (100%) rename {templates => internal/templates}/EPL-2.0.tmpl (100%) rename {templates => internal/templates}/EUPL-1.1.tmpl (100%) rename {templates => internal/templates}/EUPL-1.2.tmpl (100%) rename {templates => internal/templates}/GFDL-1.3.tmpl (100%) rename {templates => internal/templates}/GPL-2.0.tmpl (100%) rename {templates => internal/templates}/GPL-3.0.tmpl (100%) rename {templates => internal/templates}/ISC.tmpl (100%) rename {templates => internal/templates}/LGPL-2.1.tmpl (100%) rename {templates => internal/templates}/LGPL-3.0.tmpl (100%) rename {templates => internal/templates}/LPPL-1.3c.tmpl (100%) rename {templates => internal/templates}/MIT-0.tmpl (100%) rename {templates => internal/templates}/MIT.tmpl (100%) rename {templates => internal/templates}/MPL-2.0.tmpl (100%) rename {templates => internal/templates}/MS-PL.tmpl (100%) rename {templates => internal/templates}/MS-RL.tmpl (100%) rename {templates => internal/templates}/MulanPSL-2.0.tmpl (100%) rename {templates => internal/templates}/NCSA.tmpl (100%) rename {templates => internal/templates}/ODbL-1.0.tmpl (100%) rename {templates => internal/templates}/OFL-1.1.tmpl (100%) rename {templates => internal/templates}/OSL-3.0.tmpl (100%) rename {templates => internal/templates}/PostgreSQL.tmpl (100%) rename {templates => internal/templates}/UPL-1.0.tmpl (100%) rename {templates => internal/templates}/Unlicense.tmpl (100%) rename {templates => internal/templates}/Vim.tmpl (100%) rename {templates => internal/templates}/WTFPL.tmpl (100%) rename {templates => internal/templates}/Zlib.tmpl (100%) diff --git a/cmd/add.go b/cmd/add.go new file mode 100644 index 0000000..209c722 --- /dev/null +++ b/cmd/add.go @@ -0,0 +1,52 @@ +package cmd + +import ( + "fmt" + "os" + + "git.brono.cloud/wzykubek/licensmith/internal" + + "github.com/spf13/cobra" +) + +var AuthorName string +var AuthorEmail string +var OutputFile string + +func init() { + rootCmd.AddCommand(addCmd) + addCmd.Flags().StringVar(&AuthorName, "name", "", "Author name (read from Git by default)") + addCmd.Flags().StringVar(&AuthorEmail, "email", "", "Author email (read from Git by default)") + addCmd.Flags().StringVarP(&OutputFile, "output", "o", "LICENSE", "Output file") +} + +var addCmd = &cobra.Command{ + Use: "add [license]", + Short: "Add LICENSE based on SPDX ID", + Args: cobra.ExactArgs(1), + Run: func(cmd *cobra.Command, args []string) { + licenseID := args[0] + + licenseCtx, err := internal.NewLicenseContext(AuthorName, AuthorEmail) + if err != nil && err.Error() == "can't read Git config" { + fmt.Println("Error: Can't read Git config") + os.Exit(3) + } + + licenser := internal.Licenser{ + LicenseID: licenseID, + LicenseContext: licenseCtx, + OutputFile: OutputFile, + } + + err = licenser.Generate() + if err != nil && err.Error() == "usupported license" { + fmt.Printf("Error: There is no '%s' license\n", licenseID) + os.Exit(2) + } + + if err = licenser.WriteFile(); err != nil { + panic(err) + } + }, +} diff --git a/cmd/list.go b/cmd/list.go new file mode 100644 index 0000000..5c92766 --- /dev/null +++ b/cmd/list.go @@ -0,0 +1,23 @@ +package cmd + +import ( + "fmt" + "strings" + + "git.brono.cloud/wzykubek/licensmith/internal" + + "github.com/spf13/cobra" +) + +func init() { + rootCmd.AddCommand(listCmd) +} + +var listCmd = &cobra.Command{ + Use: "list", + Short: "List available licenses", + Run: func(cmd *cobra.Command, args []string) { + tmplList := internal.ListTemplates() + fmt.Println(strings.Join(tmplList, ", ")) + }, +} diff --git a/cmd/root.go b/cmd/root.go new file mode 100644 index 0000000..2b890c8 --- /dev/null +++ b/cmd/root.go @@ -0,0 +1,21 @@ +package cmd + +import ( + "fmt" + "os" + + "github.com/spf13/cobra" +) + +var rootCmd = &cobra.Command{ + Use: "licensmith", + Short: "Licensmith is a LICENSE generator", + Long: "Effortlessly craft the perfect LICENSE for your Git repo in seconds with a single command!", +} + +func Execute() { + if err := rootCmd.Execute(); err != nil { + fmt.Println(err) + os.Exit(1) + } +} diff --git a/go.mod b/go.mod index c16dd31..a64d20f 100644 --- a/go.mod +++ b/go.mod @@ -2,4 +2,12 @@ module git.brono.cloud/wzykubek/licensmith go 1.23.4 -require gopkg.in/yaml.v3 v3.0.1 // indirect +require ( + github.com/spf13/cobra v1.8.1 + gopkg.in/yaml.v3 v3.0.1 +) + +require ( + github.com/inconshreveable/mousetrap v1.1.0 // indirect + github.com/spf13/pflag v1.0.5 // indirect +) diff --git a/go.sum b/go.sum index 4bc0337..a01295b 100644 --- a/go.sum +++ b/go.sum @@ -1,3 +1,12 @@ +github.com/cpuguy83/go-md2man/v2 v2.0.4/go.mod h1:tgQtvFlXSQOSOSIRvRPT7W67SCa46tRHOmNcaadrF8o= +github.com/inconshreveable/mousetrap v1.1.0 h1:wN+x4NVGpMsO7ErUn/mUI3vEoE6Jt13X2s0bqwp9tc8= +github.com/inconshreveable/mousetrap v1.1.0/go.mod h1:vpF70FUmC8bwa3OWnCshd2FqLfsEA9PFc4w1p2J65bw= +github.com/russross/blackfriday/v2 v2.1.0/go.mod h1:+Rmxgy9KzJVeS9/2gXHxylqXiyQDYRxCVz55jmeOWTM= +github.com/spf13/cobra v1.8.1 h1:e5/vxKd/rZsfSJMUX1agtjeTDf+qv1/JdBF8gg5k9ZM= +github.com/spf13/cobra v1.8.1/go.mod h1:wHxEcudfqmLYa8iTfL+OuZPbBZkmvliBWKIezN3kD9Y= +github.com/spf13/pflag v1.0.5 h1:iy+VFUOCP1a+8yFto/drg2CJ5u0yRoB7fZw3DKv/JXA= +github.com/spf13/pflag v1.0.5/go.mod h1:McXfInJRrz4CZXVZOBLb0bTZqETkiAhM9Iw0y3An2Bg= +gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= diff --git a/git_utils.go b/internal/git_utils.go similarity index 94% rename from git_utils.go rename to internal/git_utils.go index e51e3fa..d479ba0 100644 --- a/git_utils.go +++ b/internal/git_utils.go @@ -1,4 +1,4 @@ -package main +package internal import ( "errors" diff --git a/license_context.go b/internal/license_context.go similarity index 96% rename from license_context.go rename to internal/license_context.go index b8a885d..01f789f 100644 --- a/license_context.go +++ b/internal/license_context.go @@ -1,4 +1,4 @@ -package main +package internal import ( "time" diff --git a/licenser.go b/internal/licenser.go similarity index 95% rename from licenser.go rename to internal/licenser.go index 08983c8..8181c0a 100644 --- a/licenser.go +++ b/internal/licenser.go @@ -1,4 +1,4 @@ -package main +package internal import ( "bytes" @@ -19,7 +19,7 @@ type Licenser struct { func (l *Licenser) ParseTemplate() (LicenseTemplate, error) { tmplPath := "templates/" + l.LicenseID + ".tmpl" - data, err := TemplatesDir.ReadFile(tmplPath) + data, err := EmbedFS.ReadFile(tmplPath) if err != nil { return LicenseTemplate{}, err } diff --git a/templates.go b/internal/templates.go similarity index 69% rename from templates.go rename to internal/templates.go index e6251fa..148db6e 100644 --- a/templates.go +++ b/internal/templates.go @@ -1,4 +1,4 @@ -package main +package internal import ( "embed" @@ -6,8 +6,8 @@ import ( "strings" ) -//go:embed all:templates -var TemplatesDir embed.FS +//go:embed templates/* +var EmbedFS embed.FS type LicenseTemplate struct { Title string `yaml:"title"` @@ -19,8 +19,8 @@ type LicenseTemplate struct { Body string } -func listTemplates() []string { - files, err := fs.ReadDir(TemplatesDir, "templates") +func ListTemplates() []string { + files, err := fs.ReadDir(EmbedFS, "templates") if err != nil { panic(err) } @@ -32,8 +32,3 @@ func listTemplates() []string { return tmplList } - -func listLicenses() { - tmplList := listTemplates() - println(strings.Join(tmplList, ", ")) -} diff --git a/templates/0BSD.tmpl b/internal/templates/0BSD.tmpl similarity index 100% rename from templates/0BSD.tmpl rename to internal/templates/0BSD.tmpl diff --git a/templates/AFL-3.0.tmpl b/internal/templates/AFL-3.0.tmpl similarity index 100% rename from templates/AFL-3.0.tmpl rename to internal/templates/AFL-3.0.tmpl diff --git a/templates/AGPL-3.0.tmpl b/internal/templates/AGPL-3.0.tmpl similarity index 100% rename from templates/AGPL-3.0.tmpl rename to internal/templates/AGPL-3.0.tmpl diff --git a/templates/Apache-2.0.tmpl b/internal/templates/Apache-2.0.tmpl similarity index 100% rename from templates/Apache-2.0.tmpl rename to internal/templates/Apache-2.0.tmpl diff --git a/templates/Artistic-2.0.tmpl b/internal/templates/Artistic-2.0.tmpl similarity index 100% rename from templates/Artistic-2.0.tmpl rename to internal/templates/Artistic-2.0.tmpl diff --git a/templates/BSD-2-Clause-Patent.tmpl b/internal/templates/BSD-2-Clause-Patent.tmpl similarity index 100% rename from templates/BSD-2-Clause-Patent.tmpl rename to internal/templates/BSD-2-Clause-Patent.tmpl diff --git a/templates/BSD-2-Clause.tmpl b/internal/templates/BSD-2-Clause.tmpl similarity index 100% rename from templates/BSD-2-Clause.tmpl rename to internal/templates/BSD-2-Clause.tmpl diff --git a/templates/BSD-3-Clause-Clear.tmpl b/internal/templates/BSD-3-Clause-Clear.tmpl similarity index 100% rename from templates/BSD-3-Clause-Clear.tmpl rename to internal/templates/BSD-3-Clause-Clear.tmpl diff --git a/templates/BSD-3-Clause.tmpl b/internal/templates/BSD-3-Clause.tmpl similarity index 100% rename from templates/BSD-3-Clause.tmpl rename to internal/templates/BSD-3-Clause.tmpl diff --git a/templates/BSD-4-Clause.tmpl b/internal/templates/BSD-4-Clause.tmpl similarity index 100% rename from templates/BSD-4-Clause.tmpl rename to internal/templates/BSD-4-Clause.tmpl diff --git a/templates/BSL-1.0.tmpl b/internal/templates/BSL-1.0.tmpl similarity index 100% rename from templates/BSL-1.0.tmpl rename to internal/templates/BSL-1.0.tmpl diff --git a/templates/BlueOak-1.0.0.tmpl b/internal/templates/BlueOak-1.0.0.tmpl similarity index 100% rename from templates/BlueOak-1.0.0.tmpl rename to internal/templates/BlueOak-1.0.0.tmpl diff --git a/templates/CC-BY-4.0.tmpl b/internal/templates/CC-BY-4.0.tmpl similarity index 100% rename from templates/CC-BY-4.0.tmpl rename to internal/templates/CC-BY-4.0.tmpl diff --git a/templates/CC-BY-SA-4.0.tmpl b/internal/templates/CC-BY-SA-4.0.tmpl similarity index 100% rename from templates/CC-BY-SA-4.0.tmpl rename to internal/templates/CC-BY-SA-4.0.tmpl diff --git a/templates/CC0-1.0.tmpl b/internal/templates/CC0-1.0.tmpl similarity index 100% rename from templates/CC0-1.0.tmpl rename to internal/templates/CC0-1.0.tmpl diff --git a/templates/CECILL-2.1.tmpl b/internal/templates/CECILL-2.1.tmpl similarity index 100% rename from templates/CECILL-2.1.tmpl rename to internal/templates/CECILL-2.1.tmpl diff --git a/templates/CERN-OHL-P-2.0.tmpl b/internal/templates/CERN-OHL-P-2.0.tmpl similarity index 100% rename from templates/CERN-OHL-P-2.0.tmpl rename to internal/templates/CERN-OHL-P-2.0.tmpl diff --git a/templates/CERN-OHL-S-2.0.tmpl b/internal/templates/CERN-OHL-S-2.0.tmpl similarity index 100% rename from templates/CERN-OHL-S-2.0.tmpl rename to internal/templates/CERN-OHL-S-2.0.tmpl diff --git a/templates/CERN-OHL-W-2.0.tmpl b/internal/templates/CERN-OHL-W-2.0.tmpl similarity index 100% rename from templates/CERN-OHL-W-2.0.tmpl rename to internal/templates/CERN-OHL-W-2.0.tmpl diff --git a/templates/ECL-2.0.tmpl b/internal/templates/ECL-2.0.tmpl similarity index 100% rename from templates/ECL-2.0.tmpl rename to internal/templates/ECL-2.0.tmpl diff --git a/templates/EPL-1.0.tmpl b/internal/templates/EPL-1.0.tmpl similarity index 100% rename from templates/EPL-1.0.tmpl rename to internal/templates/EPL-1.0.tmpl diff --git a/templates/EPL-2.0.tmpl b/internal/templates/EPL-2.0.tmpl similarity index 100% rename from templates/EPL-2.0.tmpl rename to internal/templates/EPL-2.0.tmpl diff --git a/templates/EUPL-1.1.tmpl b/internal/templates/EUPL-1.1.tmpl similarity index 100% rename from templates/EUPL-1.1.tmpl rename to internal/templates/EUPL-1.1.tmpl diff --git a/templates/EUPL-1.2.tmpl b/internal/templates/EUPL-1.2.tmpl similarity index 100% rename from templates/EUPL-1.2.tmpl rename to internal/templates/EUPL-1.2.tmpl diff --git a/templates/GFDL-1.3.tmpl b/internal/templates/GFDL-1.3.tmpl similarity index 100% rename from templates/GFDL-1.3.tmpl rename to internal/templates/GFDL-1.3.tmpl diff --git a/templates/GPL-2.0.tmpl b/internal/templates/GPL-2.0.tmpl similarity index 100% rename from templates/GPL-2.0.tmpl rename to internal/templates/GPL-2.0.tmpl diff --git a/templates/GPL-3.0.tmpl b/internal/templates/GPL-3.0.tmpl similarity index 100% rename from templates/GPL-3.0.tmpl rename to internal/templates/GPL-3.0.tmpl diff --git a/templates/ISC.tmpl b/internal/templates/ISC.tmpl similarity index 100% rename from templates/ISC.tmpl rename to internal/templates/ISC.tmpl diff --git a/templates/LGPL-2.1.tmpl b/internal/templates/LGPL-2.1.tmpl similarity index 100% rename from templates/LGPL-2.1.tmpl rename to internal/templates/LGPL-2.1.tmpl diff --git a/templates/LGPL-3.0.tmpl b/internal/templates/LGPL-3.0.tmpl similarity index 100% rename from templates/LGPL-3.0.tmpl rename to internal/templates/LGPL-3.0.tmpl diff --git a/templates/LPPL-1.3c.tmpl b/internal/templates/LPPL-1.3c.tmpl similarity index 100% rename from templates/LPPL-1.3c.tmpl rename to internal/templates/LPPL-1.3c.tmpl diff --git a/templates/MIT-0.tmpl b/internal/templates/MIT-0.tmpl similarity index 100% rename from templates/MIT-0.tmpl rename to internal/templates/MIT-0.tmpl diff --git a/templates/MIT.tmpl b/internal/templates/MIT.tmpl similarity index 100% rename from templates/MIT.tmpl rename to internal/templates/MIT.tmpl diff --git a/templates/MPL-2.0.tmpl b/internal/templates/MPL-2.0.tmpl similarity index 100% rename from templates/MPL-2.0.tmpl rename to internal/templates/MPL-2.0.tmpl diff --git a/templates/MS-PL.tmpl b/internal/templates/MS-PL.tmpl similarity index 100% rename from templates/MS-PL.tmpl rename to internal/templates/MS-PL.tmpl diff --git a/templates/MS-RL.tmpl b/internal/templates/MS-RL.tmpl similarity index 100% rename from templates/MS-RL.tmpl rename to internal/templates/MS-RL.tmpl diff --git a/templates/MulanPSL-2.0.tmpl b/internal/templates/MulanPSL-2.0.tmpl similarity index 100% rename from templates/MulanPSL-2.0.tmpl rename to internal/templates/MulanPSL-2.0.tmpl diff --git a/templates/NCSA.tmpl b/internal/templates/NCSA.tmpl similarity index 100% rename from templates/NCSA.tmpl rename to internal/templates/NCSA.tmpl diff --git a/templates/ODbL-1.0.tmpl b/internal/templates/ODbL-1.0.tmpl similarity index 100% rename from templates/ODbL-1.0.tmpl rename to internal/templates/ODbL-1.0.tmpl diff --git a/templates/OFL-1.1.tmpl b/internal/templates/OFL-1.1.tmpl similarity index 100% rename from templates/OFL-1.1.tmpl rename to internal/templates/OFL-1.1.tmpl diff --git a/templates/OSL-3.0.tmpl b/internal/templates/OSL-3.0.tmpl similarity index 100% rename from templates/OSL-3.0.tmpl rename to internal/templates/OSL-3.0.tmpl diff --git a/templates/PostgreSQL.tmpl b/internal/templates/PostgreSQL.tmpl similarity index 100% rename from templates/PostgreSQL.tmpl rename to internal/templates/PostgreSQL.tmpl diff --git a/templates/UPL-1.0.tmpl b/internal/templates/UPL-1.0.tmpl similarity index 100% rename from templates/UPL-1.0.tmpl rename to internal/templates/UPL-1.0.tmpl diff --git a/templates/Unlicense.tmpl b/internal/templates/Unlicense.tmpl similarity index 100% rename from templates/Unlicense.tmpl rename to internal/templates/Unlicense.tmpl diff --git a/templates/Vim.tmpl b/internal/templates/Vim.tmpl similarity index 100% rename from templates/Vim.tmpl rename to internal/templates/Vim.tmpl diff --git a/templates/WTFPL.tmpl b/internal/templates/WTFPL.tmpl similarity index 100% rename from templates/WTFPL.tmpl rename to internal/templates/WTFPL.tmpl diff --git a/templates/Zlib.tmpl b/internal/templates/Zlib.tmpl similarity index 100% rename from templates/Zlib.tmpl rename to internal/templates/Zlib.tmpl diff --git a/main.go b/main.go index a7de33b..79d9738 100644 --- a/main.go +++ b/main.go @@ -1,52 +1,9 @@ package main import ( - "flag" - "fmt" - "os" + "git.brono.cloud/wzykubek/licensmith/cmd" ) func main() { - OutputFile := flag.String("output", "LICENSE", "Specify different output file") - LicenseID := flag.String("license", "", "Specify license by SPDX ID (e.g. BSD-3-Clause)") - 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)") - ListLicenses := flag.Bool("list", false, "List available licenses") - flag.Parse() - - if *ListLicenses { - listLicenses() - os.Exit(0) - } - - if *LicenseID == "" { - fmt.Printf("Error: No license specified\n\nUse --license LICENSE\n\nAvailable licenses:\n") - listLicenses() - os.Exit(1) - } - - 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) - } - - licenser := Licenser{ - LicenseID: *LicenseID, - LicenseContext: licenseCtx, - OutputFile: *OutputFile, - } - - err = licenser.Generate() - if err != nil && err.Error() == "usupported license" { - fmt.Printf("Error: There is no '%s' license\n\nAvailable licenses:\n", *LicenseID) - listLicenses() - os.Exit(2) - } - - if err = licenser.WriteFile(); err != nil { - panic(err) - } + cmd.Execute() }