ignore
1package cmd
2
3import (
4"fmt"
5"github.com/spf13/cobra"
6"log"
7"os"
8)
9
10func init() {
11rootCmd.AddCommand(createCmd)
12}
13
14var createCmd = &cobra.Command{
15Use: "create [filename]",
16Short: "Create .ignore file",
17Run: func(cmd *cobra.Command, args []string) {
18_, err := os.Stat("./." + args[0] + "ignore")
19if err != nil {
20if os.IsNotExist(err) {
21} else {
22log.Fatal("Error:", err)
23}
24} else {
25log.Fatal("This file already exists")
26}
27_, err = os.Create("." + args[0] + "ignore")
28if err != nil {
29log.Fatal("An error has occurred")
30}
31
32fmt.Println("." + args[0] + "ignore was created successfully")
33},
34}
35