-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathmain.go
More file actions
112 lines (86 loc) · 1.91 KB
/
main.go
File metadata and controls
112 lines (86 loc) · 1.91 KB
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
package main
import (
"fmt"
"github.com/briandowns/spinner"
"github.com/spf13/cobra"
"runtime"
"time"
)
var Spinner = spinner.New(spinner.CharSets[43], 100*time.Millisecond)
var Log = NewLogger()
var (
version = "dev"
commit = "none"
date = "unknown"
builtBy = "unknown"
)
func main() {
var file string
var path string
var share bool
var info = fmt.Sprintf(
"code-playground %s (%s, %s, %s) on %s (%s)",
version,
builtBy,
date,
commit,
runtime.GOOS,
runtime.GOARCH,
)
var evaluate = func(playground IPlayground) {
init := playground.Default()
if len(path) > 0 {
init = playground.Import(path)
}
editor := NewEditor(file, playground.Type(), init)
code, err := editor.Open()
if err != nil {
Log.Error(err)
return
}
playground.Init(code)
playground.Evaluate()
if share {
playground.Share()
}
}
var cmd = &cobra.Command{
Use: "play",
Args: cobra.NoArgs,
Run: func(cmd *cobra.Command, args []string) {
},
}
var goCmd = &cobra.Command{
Use: "go",
Args: cobra.OnlyValidArgs,
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
file = args[0]
}
evaluate(new(Go))
},
}
var rustCmd = &cobra.Command{
Use: "rust",
Args: cobra.OnlyValidArgs,
Run: func(cmd *cobra.Command, args []string) {
if len(args) > 0 {
file = args[0]
}
evaluate(new(Rust))
},
}
var versionCmd = &cobra.Command{
Use: "version",
Short: "Print the version number of code-playground",
Run: func(cmd *cobra.Command, args []string) {
fmt.Println(info)
},
}
goCmd.Flags().BoolVarP(&share, "share", "s", false, "share playground")
goCmd.Flags().StringVarP(&path, "import", "i", "", "import playground")
rustCmd.Flags().BoolVarP(&share, "share", "s", false, "share playground")
rustCmd.Flags().StringVarP(&path, "import", "i", "", "import playground")
cmd.AddCommand(goCmd, rustCmd, versionCmd)
_ = cmd.Execute()
}