mirror of
https://github.com/SagerNet/sing-box.git
synced 2024-11-16 02:22:21 +08:00
Add version command
This commit is contained in:
parent
718b4afbf3
commit
792dc83778
|
@ -13,7 +13,7 @@ import (
|
|||
|
||||
var commandCheck = &cobra.Command{
|
||||
Use: "check",
|
||||
Short: "check configuration",
|
||||
Short: "Check configuration",
|
||||
Run: checkConfiguration,
|
||||
}
|
||||
|
||||
|
|
|
@ -15,7 +15,7 @@ var commandFormatFlagWrite bool
|
|||
|
||||
var commandFormat = &cobra.Command{
|
||||
Use: "format",
|
||||
Short: "format configuration",
|
||||
Short: "Format configuration",
|
||||
Run: formatConfiguration,
|
||||
}
|
||||
|
||||
|
@ -41,7 +41,7 @@ func formatConfiguration(cmd *cobra.Command, args []string) {
|
|||
logrus.Fatal("encode config: ", err)
|
||||
}
|
||||
if !commandFormatFlagWrite {
|
||||
os.Stdout.Write(buffer.Bytes())
|
||||
os.Stdout.WriteString(buffer.String() + "\n")
|
||||
return
|
||||
}
|
||||
if bytes.Compare(configContent, buffer.Bytes()) == 0 {
|
||||
|
@ -57,5 +57,5 @@ func formatConfiguration(cmd *cobra.Command, args []string) {
|
|||
logrus.Fatal("write output: ", err)
|
||||
}
|
||||
outputPath, _ := filepath.Abs(configPath)
|
||||
os.Stderr.WriteString(outputPath)
|
||||
os.Stderr.WriteString(outputPath + "\n")
|
||||
}
|
||||
|
|
|
@ -15,7 +15,7 @@ import (
|
|||
|
||||
var commandRun = &cobra.Command{
|
||||
Use: "run",
|
||||
Short: "run service",
|
||||
Short: "Run service",
|
||||
Run: run,
|
||||
}
|
||||
|
||||
|
|
20
cmd/sing-box/cmd_version.go
Normal file
20
cmd/sing-box/cmd_version.go
Normal file
|
@ -0,0 +1,20 @@
|
|||
package main
|
||||
|
||||
import (
|
||||
"os"
|
||||
"runtime"
|
||||
|
||||
C "github.com/sagernet/sing-box/constant"
|
||||
F "github.com/sagernet/sing/common/format"
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
var commandVersion = &cobra.Command{
|
||||
Use: "version",
|
||||
Short: "Print current version of sing-box",
|
||||
Run: printVersion,
|
||||
}
|
||||
|
||||
func printVersion(cmd *cobra.Command, args []string) {
|
||||
os.Stderr.WriteString(F.ToString("sing-box version ", C.Version, " (", runtime.Version(), " ", runtime.GOOS, "/", runtime.GOARCH, ")\n"))
|
||||
}
|
|
@ -19,18 +19,24 @@ var (
|
|||
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")
|
||||
|
||||
mainCommand.AddCommand(commandRun)
|
||||
mainCommand.AddCommand(commandCheck)
|
||||
mainCommand.AddCommand(commandFormat)
|
||||
mainCommand.AddCommand(commandVersion)
|
||||
}
|
||||
|
||||
func main() {
|
||||
command := &cobra.Command{
|
||||
Use: "sing-box",
|
||||
PersistentPreRun: preRun,
|
||||
}
|
||||
command.PersistentFlags().StringVarP(&configPath, "config", "c", "config.json", "set configuration file path")
|
||||
command.PersistentFlags().StringVarP(&workingDir, "directory", "D", "", "set working directory")
|
||||
command.PersistentFlags().BoolVarP(&disableColor, "disable-color", "", false, "disable color output")
|
||||
command.AddCommand(commandRun)
|
||||
command.AddCommand(commandCheck)
|
||||
command.AddCommand(commandFormat)
|
||||
if err := command.Execute(); err != nil {
|
||||
if err := mainCommand.Execute(); err != nil {
|
||||
logrus.Fatal(err)
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue
Block a user