Compare commits
2 Commits
6e4d9acd5c
...
f1f7e62853
Author | SHA1 | Date | |
---|---|---|---|
f1f7e62853 | |||
3e75458760 |
52
cmd/add.go
52
cmd/add.go
@ -1,52 +0,0 @@
|
||||
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)
|
||||
}
|
||||
},
|
||||
}
|
23
cmd/list.go
23
cmd/list.go
@ -1,23 +0,0 @@
|
||||
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, ", "))
|
||||
},
|
||||
}
|
21
cmd/root.go
21
cmd/root.go
@ -1,21 +0,0 @@
|
||||
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)
|
||||
}
|
||||
}
|
Loading…
x
Reference in New Issue
Block a user