-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.go
55 lines (47 loc) · 1.29 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
package main
import (
"GoCrab/filesys"
"GoCrab/log"
"fmt"
"os"
"github.com/spf13/cobra"
)
var outputDir, outputFileName string
func main() {
logger, err := log.New()
if err != nil {
fmt.Println("Failed to start the logger", err)
return
}
// ASCII logo
logo := `
_____ _____ _____ ______ ___ ______
| __ \ _ / __ \| ___ \/ _ \ | ___ \
| | \/ | | | / \/| |_/ / /_\ \| |_/ /
| | __| | | | | | /| _ || ___ \
| |_\ \ \_/ / \__/\| |\ \| | | || |_/ /
\____/\___/ \____/\_| \_\_| |_/\____/
`
fmt.Println(logo)
rootCmd := &cobra.Command{
Use: "gocrab [file]",
Short: "GoCrab is a Rust-to-Go transpiler",
Long: `GoCrab is a CLI tool to transpile Rust code to Go code.`,
Args: cobra.MaximumNArgs(1),
Run: func(cmd *cobra.Command, args []string) {
if len(args) == 0 {
filesys.TranspileFromEditorOrInput(logger, outputDir, outputFileName)
} else {
filesys.TranspileFromFile(logger, args[0], outputDir, outputFileName)
}
},
}
// Define flags
rootCmd.Flags().StringVarP(&outputDir, "output-dir", "d", "", "Directory to save the output Go file")
rootCmd.Flags().StringVarP(&outputFileName, "output-file", "o", "", "Name of the output Go file")
// Execute CLI
if err := rootCmd.Execute(); err != nil {
logger.Error(err.Error())
os.Exit(1)
}
}