-
Notifications
You must be signed in to change notification settings - Fork 338
/
daemon.go
65 lines (59 loc) · 1.67 KB
/
daemon.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
/*----------------------------------------------------------------
* Copyright (c) ThoughtWorks, Inc.
* Licensed under the Apache License, Version 2.0
* See LICENSE in the project root for license information.
*----------------------------------------------------------------*/
package cmd
import (
"os"
"github.com/getgauge/gauge/api"
"github.com/getgauge/gauge/api/infoGatherer"
"github.com/getgauge/gauge/api/lang"
"github.com/getgauge/gauge/config"
"github.com/getgauge/gauge/logger"
"github.com/getgauge/gauge/util"
"github.com/spf13/cobra"
)
const (
isDaemon = "IS_DAEMON"
)
var (
daemonCmd = &cobra.Command{
Use: "daemon [flags] <port> [args]",
Short: "Run as a daemon",
Long: `Run as a daemon.`,
Example: " gauge daemon 1234",
Run: func(cmd *cobra.Command, args []string) {
err := os.Setenv(isDaemon, "true")
if err != nil {
exit(err, "Unable to set Daemon=true")
}
if err := config.SetProjectRoot(args); err != nil {
exit(err, cmd.UsageString())
}
loadEnvAndReinitLogger(cmd)
if lsp {
lang.Start(&infoGatherer.SpecInfoGatherer{SpecDirs: getSpecsDir(args)}, logLevel)
return
}
port := ""
specs := util.GetSpecDirs()
if len(args) > 0 {
port = args[0]
specs = getSpecsDir(args[1:])
}
api.RunInBackground(port, specs)
},
PersistentPostRun: func(cmd *cobra.Command, args []string) { /* noop */ },
DisableAutoGenTag: true,
}
lsp bool
)
func init() {
GaugeCmd.AddCommand(daemonCmd)
daemonCmd.Flags().BoolVarP(&lsp, "lsp", "", false, "Start language server")
err := daemonCmd.Flags().MarkHidden("lsp")
if err != nil {
logger.Fatalf(true, "Unable to hide `--lsp` flag: %s", err.Error())
}
}