-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmain.go
43 lines (38 loc) · 794 Bytes
/
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
package main
import (
"embed"
"fmt"
"os"
"path"
)
func usage() {
msg := `
Usage: goignore [PROJECT TYPE]
Types Available: go,node,python,c,cpp
Example: goignore go
`
fmt.Println(msg)
}
//go:embed ignore
var IgnoreFS embed.FS
func generate(lang string) error {
f, err := IgnoreFS.ReadFile(path.Join("ignore", fmt.Sprintf("%s.gitignore", lang)))
if err != nil {
return fmt.Errorf("There is no .gitignore for %s", lang)
}
if err := os.WriteFile(".gitignore", f, os.ModePerm); err != nil {
return fmt.Errorf("failed to write file %s", err.Error())
}
return nil
}
func main() {
if len(os.Args) != 2 {
usage()
return
}
if err := generate(os.Args[1]); err != nil {
fmt.Println(err.Error())
return
}
fmt.Printf("Created .gitignore file for %s 🎉\n", os.Args[1])
}