Skip to content

Commit

Permalink
Add check config cmd
Browse files Browse the repository at this point in the history
  • Loading branch information
0xConsumer committed Jan 14, 2024
1 parent f6a6acb commit 127c0b7
Showing 1 changed file with 22 additions and 0 deletions.
22 changes: 22 additions & 0 deletions cmd/cmd_config.go
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ import (
"path/filepath"

"github.com/hiddify/libcore/shared"
"github.com/sagernet/sing-box/experimental/libbox"
"github.com/sagernet/sing-box/log"
"github.com/sagernet/sing-box/option"

Expand All @@ -29,8 +30,21 @@ var commandBuild = &cobra.Command{
},
}

var commandCheck = &cobra.Command{
Use: "check",
Short: "Check configuration",
Args: cobra.ExactArgs(1),
Run: func(cmd *cobra.Command, args []string) {
err := check(args[0])
if err != nil {
log.Fatal(err)
}
},
}

func init() {
mainCommand.AddCommand(commandBuild)
mainCommand.AddCommand(commandCheck)
}

func build(path string, optionsPath string) error {
Expand Down Expand Up @@ -60,6 +74,14 @@ func build(path string, optionsPath string) error {
return err
}

func check(path string) error {
content, err := os.ReadFile(path)
if err != nil {
return err
}
return libbox.CheckConfig(string(content))
}

func readConfigAt(path string) (*option.Options, error) {
content, err := os.ReadFile(path)
if err != nil {
Expand Down

0 comments on commit 127c0b7

Please sign in to comment.