This repository was archived by the owner on Dec 6, 2023. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 30
/
Copy pathmain.go
147 lines (137 loc) · 4.71 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
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
package main
import (
"fmt"
"os"
"time"
"github.com/pkg/browser"
log "github.com/sirupsen/logrus"
"gopkg.in/alecthomas/kingpin.v2"
)
var (
// global flags
verboseFlag = kingpin.Flag("verbose", "Verbose Output").Short('v').Default("false").Bool()
// hidden global flags
useDefaultAPIKey = kingpin.Flag("use-default-api-key", "Use Default Whisk Api Key").Hidden().Default("false").Bool()
skipDockerVersion = kingpin.Flag("skip-docker-version", "Skip check of docker version").Short('D').Default("false").Bool()
skipPullImages = kingpin.Flag("skip-pull-images", "skip pull images").Short('P').Default("false").Bool()
skipOpenBrowser = kingpin.Flag("skip-open-browser", "skip pull images").Short('B').Default("false").Bool()
skipIde = kingpin.Flag("skip-ide", "skip starting ide").Short('I').Default("false").Bool()
useVersion = kingpin.Flag("use-version", "use the given version of images").Short('V').Default("").String()
// hidden debug commands
debugCmd = kingpin.Command("debug", "debug").Hidden()
wskProps = debugCmd.Command("wskprops", "Create WskProps file").Hidden()
ideDeployCmd = debugCmd.Command("ide-deploy", "Create IDE deployment").Hidden()
ideDestroyCmd = debugCmd.Command("ide-destroy", "Destroy IDE deployment").Hidden()
whiskDeployCmd = debugCmd.Command("whisk-deploy", "Create Whisk deployment").Hidden()
whiskDestroyCmd = debugCmd.Command("whisk-destroy", "Destroy Whisk deployment").Hidden()
redisDeployCmd = debugCmd.Command("redis-deploy", "Create Redis deployment").Hidden()
redisDestroyCmd = debugCmd.Command("redis-destroy", "Destroy Redis deployment").Hidden()
inputCmd = debugCmd.Command("input", "Input test").Hidden()
inputArgCmd = inputCmd.Arg("input arg", "input arg").Default("").String()
inputSelectFlag = inputCmd.Flag("select", "select").Bool()
// start, stop, init and status
startCmd = kingpin.Command("start", "Start Development Enviroment")
// init
initCmd = kingpin.Command("init", "Initialise SDK Repository and related informations")
initDirArg = initCmd.Arg("directory", "work directory").Default("").String()
initRepoArg = initCmd.Arg("repo", "Repository").Default("").String()
initWhiskKeyFlag = initCmd.Flag("whisk-apikey", "Whisk API Key").Default("").String()
initIOKeyFlag = initCmd.Flag("io-apikey", "IO API Key").Default("").String()
initWskPropsFlag = initCmd.Flag("wskprops", "Write .wskprops").Default("false").Bool()
// stop
stopCmd = kingpin.Command("stop", "Stop Development Environment")
// restart
restartCmd = kingpin.Command("restart", "Restart Development Environment")
// status
statusCmd = kingpin.Command("status", "Check Containers Status")
)
func parseDebug(cmd string) bool {
switch cmd {
case wskProps.FullCommand():
ConfigLoad()
WskPropsSave()
case ideDeployCmd.FullCommand():
FatalIf(ConfigLoad())
info, _ := Preflight(Config.AppDir)
IdeDeploy(Config.AppDir, info)
configureIde(info)
case ideDestroyCmd.FullCommand():
IdeDestroy()
case whiskDeployCmd.FullCommand():
FatalIf(ConfigLoad())
WhiskDeploy()
WhiskUpdatePackageParameters("iosdk", ConfigMap())
case whiskDestroyCmd.FullCommand():
WhiskDestroy()
case redisDeployCmd.FullCommand():
RedisDeploy()
case redisDestroyCmd.FullCommand():
RedisDestroy()
case inputCmd.FullCommand():
if !*inputSelectFlag {
fmt.Printf("result: '%s'\n", Input("Input Test", *inputArgCmd))
} else {
fmt.Printf("select: '%s'\n", Select("Select Test", *inputArgCmd))
}
default:
return false
}
return true
}
func parse(cmd string) {
// debugging (hidden) commands
if parseDebug(cmd) {
return
}
// user visible commands
switch cmd {
// Start
case startCmd.FullCommand():
info, err := Start()
ShowError(err)
if err == nil {
PropagateConfig(info)
if !*skipOpenBrowser {
time.Sleep(2 * time.Second)
browser.OpenURL(BrowserURL)
}
}
// Stop
case stopCmd.FullCommand():
Stop()
case restartCmd.FullCommand():
Stop()
info, err := Start()
ShowError(err)
if err == nil {
PropagateConfig(info)
}
fmt.Println("\nRestarted, please reload the browser.")
// Init
case initCmd.FullCommand():
dir, err := Init(*initDirArg, *initRepoArg, os.Stderr)
if err == nil {
err = Configure(dir)
}
ShowError(err)
// Status
case statusCmd.FullCommand():
dockerStatus("iosdk-openwhisk")
dockerStatus("iosdk-redis")
dockerStatus("iosdk-theia")
}
}
// Main entrypoint for wskide
func Main(version string) {
kingpin.UsageTemplate(kingpin.CompactUsageTemplate).Version(version).Author(Author)
kingpin.HelpFlag.Short('h')
kingpin.CommandLine.Help = Description
cmd := kingpin.Parse()
if *verboseFlag {
log.SetLevel(log.TraceLevel)
}
if *useVersion != "" {
Version = *useVersion
}
parse(cmd)
}