sing-box/cmd/sing-box/cmd_check.go

44 lines
684 B
Go
Raw Normal View History

2022-07-04 08:59:27 +00:00
package main
import (
"context"
"github.com/sagernet/sing-box"
2022-07-12 07:17:29 +00:00
"github.com/sagernet/sing-box/log"
2022-07-06 07:01:09 +00:00
2022-07-04 08:59:27 +00:00
"github.com/spf13/cobra"
)
var commandCheck = &cobra.Command{
Use: "check",
2022-07-04 09:08:28 +00:00
Short: "Check configuration",
2022-08-13 10:36:49 +00:00
Run: func(cmd *cobra.Command, args []string) {
err := check()
if err != nil {
log.Fatal(err)
}
},
Args: cobra.NoArgs,
2022-07-04 08:59:27 +00:00
}
2022-08-13 10:36:49 +00:00
func init() {
mainCommand.AddCommand(commandCheck)
}
func check() error {
2023-03-18 11:15:28 +00:00
options, err := readConfigAndMerge()
2022-07-04 08:59:27 +00:00
if err != nil {
2022-08-19 07:42:29 +00:00
return err
2022-07-04 08:59:27 +00:00
}
2024-11-07 11:58:46 +00:00
ctx, cancel := context.WithCancel(globalCtx)
2023-04-03 10:24:20 +00:00
instance, err := box.New(box.Options{
Context: ctx,
Options: options,
})
2023-03-05 03:26:19 +00:00
if err == nil {
instance.Close()
}
2022-07-04 08:59:27 +00:00
cancel()
2022-08-13 10:36:49 +00:00
return err
2022-07-04 08:59:27 +00:00
}