mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-29 12:01:29 +00:00
42 lines
875 B
Go
42 lines
875 B
Go
package main
|
|
|
|
import (
|
|
"os"
|
|
|
|
_ "github.com/sagernet/sing-box/include"
|
|
"github.com/sagernet/sing-box/log"
|
|
|
|
"github.com/spf13/cobra"
|
|
)
|
|
|
|
var (
|
|
configPath string
|
|
workingDir string
|
|
disableColor bool
|
|
)
|
|
|
|
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")
|
|
}
|
|
|
|
func main() {
|
|
if err := mainCommand.Execute(); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func preRun(cmd *cobra.Command, args []string) {
|
|
if workingDir != "" {
|
|
if err := os.Chdir(workingDir); err != nil {
|
|
log.Fatal(err)
|
|
}
|
|
}
|
|
}
|