Files
sing-box-extended-mirror/cmd/sing-box/main.go
T

55 lines
1.2 KiB
Go
Raw Normal View History

2022-06-30 21:27:56 +08:00
package main
import (
"os"
2022-07-04 16:45:32 +08:00
"github.com/sagernet/sing-box/log"
2022-07-06 15:01:09 +08:00
2022-06-30 21:27:56 +08:00
"github.com/sirupsen/logrus"
"github.com/spf13/cobra"
)
func init() {
logrus.StandardLogger().SetLevel(logrus.TraceLevel)
2022-07-04 16:45:32 +08:00
logrus.StandardLogger().SetFormatter(&log.LogrusTextFormatter{})
2022-06-30 21:27:56 +08:00
}
2022-07-03 01:57:04 +08:00
var (
2022-07-03 03:42:57 +08:00
configPath string
workingDir string
2022-07-04 16:45:32 +08:00
disableColor bool
2022-07-03 01:57:04 +08:00
)
2022-06-30 21:27:56 +08:00
2022-07-04 17:08:28 +08:00
var mainCommand = &cobra.Command{
Use: "sing-box",
PersistentPreRun: preRun,
}
func init() {
mainCommand.PersistentFlags().StringVarP(&configPath, "config", "c", "config.json", "set configuration file path")
mainCommand.PersistentFlags().StringVarP(&workingDir, "directory", "D", "", "set working directory")
mainCommand.PersistentFlags().BoolVarP(&disableColor, "disable-color", "", false, "disable color output")
mainCommand.AddCommand(commandRun)
mainCommand.AddCommand(commandCheck)
mainCommand.AddCommand(commandFormat)
mainCommand.AddCommand(commandVersion)
}
2022-06-30 21:27:56 +08:00
func main() {
2022-07-04 17:08:28 +08:00
if err := mainCommand.Execute(); err != nil {
2022-06-30 21:27:56 +08:00
logrus.Fatal(err)
}
}
2022-07-04 16:45:32 +08:00
func preRun(cmd *cobra.Command, args []string) {
if disableColor {
logrus.StandardLogger().SetFormatter(&log.LogrusTextFormatter{DisableColors: true})
}
2022-07-03 01:57:04 +08:00
if workingDir != "" {
if err := os.Chdir(workingDir); err != nil {
logrus.Fatal(err)
}
}
2022-06-30 21:27:56 +08:00
}