2020-11-23 10:38:43 -05:00
|
|
|
package commands
|
|
|
|
|
|
|
|
import (
|
|
|
|
"fmt"
|
|
|
|
|
2022-01-02 10:16:23 -05:00
|
|
|
"github.com/v2fly/v2ray-core/v5/main/commands/base"
|
2020-11-23 10:38:43 -05:00
|
|
|
)
|
|
|
|
|
|
|
|
// CmdTest tests config files
|
|
|
|
var CmdTest = &base.Command{
|
|
|
|
CustomFlags: true,
|
2020-11-28 09:06:03 -05:00
|
|
|
UsageLine: "{{.Exec}} test [-format=json] [-c config.json] [-d dir]",
|
2021-02-21 10:02:42 -05:00
|
|
|
Short: "test config files",
|
2020-11-23 10:38:43 -05:00
|
|
|
Long: `
|
|
|
|
Test config files, without launching V2Ray server.
|
|
|
|
|
2021-03-10 16:03:26 -05:00
|
|
|
{{.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
|
|
|
|
|
2020-11-23 10:38:43 -05:00
|
|
|
Arguments:
|
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-c, -config <file>
|
2020-11-28 09:06:03 -05:00
|
|
|
Config file for V2Ray. Multiple assign is accepted.
|
2020-11-23 10:38:43 -05:00
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-d, -confdir <dir>
|
2021-03-10 16:03:26 -05:00
|
|
|
A directory with config files. Multiple assign is accepted.
|
2020-11-23 10:38:43 -05:00
|
|
|
|
2020-11-28 09:06:03 -05:00
|
|
|
-r
|
|
|
|
Load confdir recursively.
|
2020-11-23 10:38:43 -05:00
|
|
|
|
2021-02-21 10:02:42 -05:00
|
|
|
-format <format>
|
2021-03-10 16:03:26 -05:00
|
|
|
Format of config input. (default "auto")
|
2020-11-23 10:38:43 -05:00
|
|
|
|
2020-11-28 09:06:03 -05:00
|
|
|
Examples:
|
|
|
|
|
|
|
|
{{.Exec}} {{.LongName}} -c config.json
|
|
|
|
{{.Exec}} {{.LongName}} -d path/to/dir
|
|
|
|
|
|
|
|
Use "{{.Exec}} help format-loader" for more information about format.
|
|
|
|
`,
|
|
|
|
Run: executeTest,
|
2020-11-23 10:38:43 -05:00
|
|
|
}
|
|
|
|
|
|
|
|
func executeTest(cmd *base.Command, args []string) {
|
|
|
|
setConfigFlags(cmd)
|
|
|
|
cmd.Flag.Parse(args)
|
|
|
|
printVersion()
|
2021-11-06 03:48:06 -04:00
|
|
|
configFiles = getConfigFilePath()
|
|
|
|
_, err := startV2Ray()
|
2020-11-23 10:38:43 -05:00
|
|
|
if err != nil {
|
|
|
|
base.Fatalf("Test failed: %s", err)
|
|
|
|
}
|
|
|
|
fmt.Println("Configuration OK.")
|
|
|
|
}
|