Hunter0x7c7
2022-08-11 b8230139fb40edea387617b6accd8371e37eda58
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
package commands
 
import (
    "fmt"
 
    "github.com/v2fly/v2ray-core/v5/main/commands/base"
)
 
// CmdTest tests config files
var CmdTest = &base.Command{
    CustomFlags: true,
    UsageLine:   "{{.Exec}} test [-format=json] [-c config.json] [-d dir]",
    Short:       "test config files",
    Long: `
Test config files, without launching V2Ray server.
 
{{.Exec}} will also use the config directory specified by environment 
variable "v2ray.location.confdir". If no config found, it tries 
to load config from one of below:
 
    1. The default "config.json" in the current directory
    2. The config file from ENV "v2ray.location.config"
    3. The stdin if all failed above
 
Arguments:
 
    -c, -config <file>
        Config file for V2Ray. Multiple assign is accepted.
 
    -d, -confdir <dir>
        A directory with config files. Multiple assign is accepted.
 
    -r
        Load confdir recursively.
 
    -format <format>
        Format of config input. (default "auto")
 
Examples:
 
    {{.Exec}} {{.LongName}} -c config.json
    {{.Exec}} {{.LongName}} -d path/to/dir
 
Use "{{.Exec}} help format-loader" for more information about format.
    `,
    Run: executeTest,
}
 
func executeTest(cmd *base.Command, args []string) {
    setConfigFlags(cmd)
    cmd.Flag.Parse(args)
    printVersion()
    configFiles = getConfigFilePath()
    _, err := startV2Ray()
    if err != nil {
        base.Fatalf("Test failed: %s", err)
    }
    fmt.Println("Configuration OK.")
}