-
Notifications
You must be signed in to change notification settings - Fork 53
/
main.go
115 lines (101 loc) · 2.72 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
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
// 版权 @2019 凹语言 作者。保留所有权利。
//go:build !wasm
// +build !wasm
// 凹语言, The Wa Programming Language.
package main
import (
"fmt"
"os"
"strings"
"wa-lang.org/wa/internal/3rdparty/cli"
"wa-lang.org/wa/internal/app/appast"
"wa-lang.org/wa/internal/app/appbase"
"wa-lang.org/wa/internal/app/appbuild"
"wa-lang.org/wa/internal/app/appcir"
"wa-lang.org/wa/internal/app/appdap"
"wa-lang.org/wa/internal/app/appdev"
"wa-lang.org/wa/internal/app/appdoc"
"wa-lang.org/wa/internal/app/appfmt"
"wa-lang.org/wa/internal/app/appgo2wa"
"wa-lang.org/wa/internal/app/appinit"
"wa-lang.org/wa/internal/app/applex"
"wa-lang.org/wa/internal/app/applogo"
"wa-lang.org/wa/internal/app/applsp"
"wa-lang.org/wa/internal/app/appplay"
"wa-lang.org/wa/internal/app/apprun"
"wa-lang.org/wa/internal/app/appssa"
"wa-lang.org/wa/internal/app/apptest"
"wa-lang.org/wa/internal/app/appwat2wasm"
"wa-lang.org/wa/internal/app/appyacc"
"wa-lang.org/wa/internal/config"
"wa-lang.org/wa/internal/version"
)
func main() {
cliApp := cli.NewApp()
cliApp.Name = "Wa"
cliApp.Usage = "Wa is a tool for managing Wa source code."
cliApp.Copyright = "Copyright 2018 The Wa Authors. All rights reserved."
cliApp.Version = version.Version
cliApp.EnableBashCompletion = true
cliApp.HideHelpCommand = true
cliApp.CustomAppHelpTemplate = cli.AppHelpTemplate +
"\nSee \"https://wa-lang.org\" for more information.\n"
cliApp.Flags = []cli.Flag{
&cli.BoolFlag{
Name: "debug",
Aliases: []string{"d"},
Usage: "set debug mode",
},
&cli.StringFlag{
Name: "trace",
Aliases: []string{"t"},
Usage: "set trace mode (*|app|compiler|loader)",
},
}
cliApp.Before = func(c *cli.Context) error {
if c.Bool("debug") {
config.SetDebugMode()
}
if parten := c.String("trace"); parten != "" {
config.SetEnableTrace(parten)
}
return nil
}
// 没有参数时显示 help 信息
cliApp.Action = func(c *cli.Context) error {
if c.NArg() > 0 {
if c.NArg() == 1 && appbase.HasExt(c.Args().First(), ".wa", ".wat", ".wasm") {
return apprun.CmdRunAction(c)
}
fmt.Println("unknown command:", strings.Join(c.Args().Slice(), " "))
os.Exit(1)
}
cli.ShowAppHelpAndExit(c, 0)
return nil
}
cliApp.Commands = []*cli.Command{
// 用于调试(隐藏)
appdev.CmdDev,
// 用户可见子命令
appplay.CmdPlay,
appinit.CmdInit,
appbuild.CmdBuild,
apprun.CmdRun,
appfmt.CmdFmt,
apptest.CmdTest,
applsp.CmdLsp,
appyacc.CmdYacc,
applogo.CmdLogo,
// 开发者用于测试(隐藏)
applex.CmdLex,
appast.CmdAst,
appssa.CmdSsa,
appwat2wasm.CmdWat2wasm,
// 待完善的子命令(隐藏)
appgo2wa.CmdGo2wa,
appcir.CmdCir,
appdoc.CmdDoc,
appdap.CmdDap,
}
cliApp.Run(os.Args)
}