Skip to content

Commit

Permalink
Write .gitignore file
Browse files Browse the repository at this point in the history
* .gitignore content is written to file.

Signed-off-by: Gökhan Özeloğlu <gozeloglu@gmail.com>
  • Loading branch information
gozeloglu committed May 27, 2023
1 parent be62d79 commit e083a67
Show file tree
Hide file tree
Showing 2 changed files with 34 additions and 0 deletions.
21 changes: 21 additions & 0 deletions cmd/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -5,8 +5,11 @@ import (
"fmt"
"github.com/AlecAivazis/survey/v2"
"github.com/c-bata/go-prompt"
"github.com/gozeloglu/gitignore/internal/file"
"github.com/gozeloglu/gitignore/internal/http"
"log"
"os"
"path"
"strings"
)

Expand All @@ -31,6 +34,15 @@ func main() {
log.Fatalln(err)
}
fmt.Println(gitignoreFile)
dir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}

err = file.Save(path.Join(dir, ".gitignore"), []byte(gitignoreFile))
if err != nil {
log.Fatalln(err)
}
} else if flag.Arg(0) == "cli" {
t := prompt.Input(">>> ", completer, prompt.OptionPrefixTextColor(prompt.Blue))
inp := strings.Split(t, " ")
Expand All @@ -48,6 +60,15 @@ func main() {
log.Fatalln(err)
}
fmt.Println(gitignore)
dir, err := os.Getwd()
if err != nil {
log.Fatalln(err)
}

err = file.Save(path.Join(dir, ".gitignore"), []byte(gitignore))
if err != nil {
log.Fatalln(err)
}
} else {
fmt.Println(flag.Arg(0), "is wrong argument")
}
Expand Down
13 changes: 13 additions & 0 deletions internal/file/file.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
package file

import "os"

// Save writes data to dst.
func Save(dst string, data []byte) error {
err := os.WriteFile(dst, data, 0666)
if err != nil {
return err
}

return nil
}

0 comments on commit e083a67

Please sign in to comment.