github.com/gopinath-langote/1build@v1.7.0/cmd/del/delete.go (about) 1 package del 2 3 import ( 4 "bufio" 5 "fmt" 6 "os" 7 "strings" 8 9 "github.com/gopinath-langote/1build/cmd/config" 10 "github.com/gopinath-langote/1build/cmd/utils" 11 "github.com/spf13/cobra" 12 ) 13 14 var shouldDelete bool 15 16 // Cmd cobra command for delete one build configuration 17 var Cmd = &cobra.Command{ 18 Use: "delete", 19 Short: "Deletes project configuration", 20 Long: `Deletes project configuration 21 22 - To forcibly delete file without asking for consent use -f or --force 23 24 For example: 25 26 1build delete 27 1build delete --force`, 28 PreRun: func(cmd *cobra.Command, args []string) { 29 if !config.IsConfigFilePresent() { 30 utils.CPrintln("No configuration file found!", utils.Style{Color: utils.RED}) 31 //fmt.Println(utils.Colored("No configuration file found!", utils.RED)) 32 utils.ExitError() 33 } 34 }, 35 Run: func(cmd *cobra.Command, args []string) { 36 if !shouldDelete { 37 fmt.Printf("Delete 1build configuration file? (y/N) ") 38 reader := bufio.NewReader(os.Stdin) 39 prompt, err := reader.ReadString('\n') 40 if err == nil && strings.ToLower(strings.TrimSpace(prompt)) == "y" { 41 shouldDelete = true 42 } 43 } 44 if shouldDelete { 45 if err := config.DeleteConfigFile(); err != nil { 46 utils.CPrintln("Error deleting configuration file.", utils.Style{Color: utils.RED}) 47 } 48 } 49 }, 50 } 51 52 func init() { 53 Cmd.Flags().BoolVar(&shouldDelete, "force", false, "Forcibly del configuration file") 54 }