-
-
Notifications
You must be signed in to change notification settings - Fork 7
Expand file tree
/
Copy pathmain.go
More file actions
100 lines (96 loc) · 3.74 KB
/
main.go
File metadata and controls
100 lines (96 loc) · 3.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
package main
import (
"bufio"
"fmt"
"io/ioutil"
"log"
"os"
kingpin "gopkg.in/alecthomas/kingpin.v2"
)
var (
app = kingpin.New("license-up", "A command-line tool to make licences.").Version("1.0.0")
force = app.Flag("force", "Create a license even if license already exists.").Short('f').Bool()
md = app.Flag("md", "Create a license.md file instead of a license file.").Bool()
mit = app.Command("mit", "Create MIT license.")
mitName = mit.Arg("name", "Name of license holder.").Required().String()
mitSurname = mit.Arg("surname", "Surname of license holder.").Required().String()
mitWebsite = mit.Arg("website", "Website of license holder").String()
bsd2 = app.Command("bsd2", "Create BSD 2-Clause license.")
bsd2Name = bsd2.Arg("name", "Name of license holder.").Required().String()
bsd2Surname = bsd2.Arg("surname", "Surname of license holder.").Required().String()
bsd3 = app.Command("bsd3", "Create BSD 3-Clause license.")
bsd3Name = bsd3.Arg("name", "Name of license holder.").Required().String()
bsd3Surname = bsd3.Arg("surname", "Surname of license holder.").Required().String()
cc0 = app.Command("cc0", "Create CC0 license.")
unlicense = app.Command("unlicense", "Create Unlicense license.")
gpl2 = app.Command("gpl2", "Create GNU General Public License version 2.")
gpl3 = app.Command("gpl3", "Create GNU General Public License version 3.")
isc = app.Command("isc", "Create ISC license.")
iscName = isc.Arg("name", "Name of license holder.").Required().String()
iscSurname = isc.Arg("surname", "Surname of license holder.").Required().String()
wtfpl = app.Command("wtfpl", "Create WTFPL license.")
wtfplName = wtfpl.Arg("name", "Name of license holder.").Required().String()
wtfplSurname = wtfpl.Arg("surname", "Surname of license holder.").Required().String()
boml = app.Command("boml", "Create Blue Oak Model license.")
)
func main() {
kingpin.MustParse(app.Parse(os.Args[1:]))
// Check to see if the user wants to create a `license.md` file instead of a `license` file
fileName := "license"
if bool(*md) == true {
fileName = "license.md"
}
// Check to see if we are overwriting any existing license files
if bool(*force) == false {
files, err := ioutil.ReadDir(".")
if err != nil {
log.Fatal(err)
}
reader := bufio.NewReader(os.Stdin)
overwrite := false
hasLicense := false
for _, f := range files {
if f.Name() == fileName {
hasLicense = true
fmt.Print("There is already a license present in current directory. Do you want to overwrite it with a new one? [y/N] ")
text, _ := reader.ReadString('\n')
switch text {
case "y\n":
overwrite = true
case "Y\n":
overwrite = true
}
}
}
if hasLicense == true && overwrite == false {
os.Exit(0)
}
}
// Create the licenses
switch kingpin.MustParse(app.Parse(os.Args[1:])) {
case mit.FullCommand():
if string(*mitWebsite) == "" {
mitCreate(string(*mitName), string(*mitSurname), fileName)
} else {
mitCreateWithSite(string(*mitName), string(*mitSurname), string(*mitWebsite), fileName)
}
case bsd2.FullCommand():
bsd2Create(string(*bsd2Name), string(*bsd2Surname), fileName)
case bsd3.FullCommand():
bsd3Create(string(*bsd3Name), string(*bsd3Surname), fileName)
case cc0.FullCommand():
cc0Create(fileName)
case unlicense.FullCommand():
unlicenseCreate(fileName)
case gpl2.FullCommand():
gpl2Create(fileName)
case gpl3.FullCommand():
gpl3Create(fileName)
case isc.FullCommand():
iscCreate(string(*iscName), string(*iscSurname), fileName)
case wtfpl.FullCommand():
wtfplCreate(string(*wtfplName), string(*wtfplSurname), fileName)
case boml.FullCommand():
bomlCreate(fileName, bool(*md))
}
}