Skip to content

Commit

Permalink
#13 - Add command lic
Browse files Browse the repository at this point in the history
  • Loading branch information
jtprogru committed Jun 29, 2024
1 parent 8cae23f commit bd6ff2a
Show file tree
Hide file tree
Showing 2 changed files with 65 additions and 2 deletions.
62 changes: 62 additions & 0 deletions cmd/lic.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,62 @@
package cmd

import (
"os"
"text/template"
"time"

"github.com/spf13/cobra"
"github.com/spf13/viper"
)

var (
// cbrfCmd represents the cbrf command
licCmd = &cobra.Command{
Use: "lic",
Short: "Generate new WTFPL license for you project",
Long: `Just for fun! Generate new WTFPL license for LICENSE file with your email, full name and current year.`,
Run: func(cmd *cobra.Command, args []string) {

Email := viper.GetString("email")
FullName := viper.GetString("full_name")
Year, _, _ := time.Now().Date()
tmpl, err := template.New("wtfpl").Parse(licenseTpl)
if err != nil {
panic(err)
}

err = tmpl.Execute(os.Stdout, data{Email, FullName, Year})
if err != nil {
panic(err)
}
},
}
)

func init() {
rootCmd.AddCommand(licCmd)

// licCmd.Flags().BoolVarP(&showAll, "all", "a", false, "Show all rates")
}

type data struct {
Email string
FullName string
Year int
}

var licenseTpl = ` DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
Version 2, December 2004
Copyright (C) {{ .Year }} {{ .FullName }} <{{ .Email }}>
Everyone is permitted to copy and distribute verbatim or modified
copies of this license document, and changing it is allowed as long
as the name is changed.
DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION
0. You just DO WHAT THE FUCK YOU WANT TO.
`
5 changes: 3 additions & 2 deletions cmd/root.go
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,8 @@ func initConfig() {
viper.AutomaticEnv() // read in environment variables that match

// If a config file is found, read it in.
if err := viper.ReadInConfig(); err == nil {
fmt.Fprintln(os.Stderr, "Using config file:", viper.ConfigFileUsed())
err := viper.ReadInConfig()
if err != nil {
fmt.Printf("Error loading config: %s", err)
}
}

0 comments on commit bd6ff2a

Please sign in to comment.