test.go 1.3 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. package commands
  2. import (
  3. "fmt"
  4. "github.com/v2fly/v2ray-core/v5/main/commands/base"
  5. )
  6. // CmdTest tests config files
  7. var CmdTest = &base.Command{
  8. CustomFlags: true,
  9. UsageLine: "{{.Exec}} test [-format=json] [-c config.json] [-d dir]",
  10. Short: "test config files",
  11. Long: `
  12. Test config files, without launching V2Ray server.
  13. {{.Exec}} will also use the config directory specified by environment
  14. variable "v2ray.location.confdir". If no config found, it tries
  15. to load config from one of below:
  16. 1. The default "config.json" in the current directory
  17. 2. The config file from ENV "v2ray.location.config"
  18. 3. The stdin if all failed above
  19. Arguments:
  20. -c, -config <file>
  21. Config file for V2Ray. Multiple assign is accepted.
  22. -d, -confdir <dir>
  23. A directory with config files. Multiple assign is accepted.
  24. -r
  25. Load confdir recursively.
  26. -format <format>
  27. Format of config input. (default "auto")
  28. Examples:
  29. {{.Exec}} {{.LongName}} -c config.json
  30. {{.Exec}} {{.LongName}} -d path/to/dir
  31. Use "{{.Exec}} help format-loader" for more information about format.
  32. `,
  33. Run: executeTest,
  34. }
  35. func executeTest(cmd *base.Command, args []string) {
  36. setConfigFlags(cmd)
  37. cmd.Flag.Parse(args)
  38. printVersion()
  39. configFiles = getConfigFilePath()
  40. _, err := startV2Ray()
  41. if err != nil {
  42. base.Fatalf("Test failed: %s", err)
  43. }
  44. fmt.Println("Configuration OK.")
  45. }