-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
48 lines (37 loc) · 1.22 KB
/
main.go
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
package main
import (
"fmt"
"github.com/amirfakhrullah/license-gen/pkg/cli"
"github.com/amirfakhrullah/license-gen/pkg/helpers"
"github.com/amirfakhrullah/license-gen/pkg/licenses"
)
func main() {
existedLicenseList, fileErr := helpers.IsLicenseExist()
helpers.HandlePanic(&fileErr)
// get confirmation to proceed if there's existing LICENSE
if len(existedLicenseList) > 0 {
toProceed := cli.ConfirmProceed(&existedLicenseList)
if !toProceed {
return
}
}
lic := *licenses.GetLicenseList()
i := cli.Select(&lic)
name := cli.GetName()
year := cli.GetYear()
licenses.FetchFullLicense(&(lic[i].Key))
licContent := licenses.Fill_License(&name, &year)
// execute file deletion process for files in existedLicenseList with extensions (.txt, .md, ...)
delErr := helpers.DeleteExistingLicenseFiles(&existedLicenseList)
helpers.HandlePanic(&delErr)
// file writes
writeErr := helpers.CreateAndWriteLicense(licContent)
helpers.HandlePanic(&writeErr)
// mention license at the bottom of README file if needed
toMention := cli.ToMentionInReadMe()
if toMention {
mentionErr := helpers.MentionLicenseInReadme(&(lic[i].Name))
helpers.HandlePanic(&mentionErr)
}
fmt.Printf("✅ Successfully added %v\n", lic[i].Name)
}