-
Notifications
You must be signed in to change notification settings - Fork 4
/
Copy pathmain.go
56 lines (48 loc) · 1.51 KB
/
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
44
45
46
47
48
49
50
51
52
53
54
55
56
package main
import (
"context"
"fmt"
"os"
"os/signal"
"path/filepath"
"syscall"
"github.com/TejasGhatte/go-sail/cmd"
"github.com/TejasGhatte/go-sail/internal/initializers"
"github.com/spf13/cobra"
)
var rootCmd = &cobra.Command{
Use: "go-sail",
Short: "A CLI for generating project templates for Go backend frameworks",
Long: `go-sail is a CLI tool that generates project templates for Go backend frameworks like Fiber, Echo, and Gin, with pre-configured logging and caching, helping developers quickly set up and initialize projects. Users can choose their own database and ORM configurations, and go-sail generates the necessary files for the project.`,
}
func main() {
ctx, cancel := context.WithCancel(context.Background())
defer cancel()
// handling ctrl+c
sigs := make(chan os.Signal, 1)
signal.Notify(sigs, os.Interrupt, syscall.SIGTERM)
go func() {
<-sigs
cleanup(cmd.ProjectName)
cancel()
os.Exit(1)
}()
initializers.LoadConfig("config.yml")
rootCmd.AddCommand(cmd.CreateProjectCommand)
if err := rootCmd.ExecuteContext(ctx); err != nil {
fmt.Println(err)
os.Exit(1)
}
}
func cleanup(projectName string) {
fmt.Println("\nReceived interrupt signal, exiting...")
if projectName != "" {
currentDir, _ := os.Getwd()
projectDir := filepath.Join(currentDir, projectName)
if err := os.RemoveAll(projectDir); err != nil {
fmt.Printf("Failed to remove project directory %s: %v\n", projectDir, err)
} else {
fmt.Printf("Successfully removed project directory %s\n", projectDir)
}
}
}