This commit is contained in:
Chen Asraf
2022-05-18 15:51:02 +03:00
parent fda50debe1
commit 0b0f45d3c6
3 changed files with 25 additions and 2 deletions

8
.editorconfig Normal file
View File

@@ -0,0 +1,8 @@
[*]
trim_trailing_whitespace = true
insert_final_newline = true
indent_size = 2
indent_style = space
[*.md]
trim_trailing_whitespace = false

5
README.md Normal file
View File

@@ -0,0 +1,5 @@
# Gitignore File Generator
You can run this CLI program to create or append a .gitignore template easily.
Just run `gi_gen` in the directory you wish to add to and follow the prompts.

View File

@@ -14,6 +14,10 @@ import (
// create line cache map for skipping previously checked glob lines
var lineCache = make(map[string]bool)
func quit() {
os.Exit(1)
}
func main() {
allFiles, err := prepareGitignores()
@@ -29,7 +33,7 @@ func main() {
if findFileMatches(contents) {
sep := "#========================================================================\n"
header := fmt.Sprintf(sep+"# %s\n"+sep+"\n", basename)
header := fmt.Sprintf(sep+"# %s\n"+sep+"\n", langName)
files[langName] = header + contents
fileNames = append(fileNames, langName)
}
@@ -48,6 +52,9 @@ func main() {
var inp []string
survey.AskOne(prompt, &inp)
if inp == nil {
quit()
}
for _, sel := range inp {
selected = append(selected, files[sel])
@@ -64,9 +71,12 @@ func main() {
Message: ".gitignore file found in this directory. Please pick an option:",
Options: []string{"Overwrite", "Append", "Skip"},
}
var inp2 string
inp2 := ""
survey.AskOne(prompt2, &inp2)
switch inp2 {
case "":
quit()
break
case "Overwrite":
log.Printf("Writing to %s", out)
writeFile(out, strings.Join(selected, "\n"), true)