Files

55 lines
1.0 KiB
Go
Raw Permalink Normal View History

2022-07-04 17:08:28 +08:00
package main
import (
"os"
"runtime"
2022-07-06 15:01:09 +08:00
C "github.com/sagernet/sing-box/constant"
2022-07-08 23:03:57 +08:00
F "github.com/sagernet/sing/common/format"
2022-07-06 15:01:09 +08:00
2022-07-04 17:08:28 +08:00
"github.com/spf13/cobra"
)
var commandVersion = &cobra.Command{
Use: "version",
Short: "Print current version of sing-box",
Run: printVersion,
2022-08-09 14:49:17 +08:00
Args: cobra.NoArgs,
2022-07-04 17:08:28 +08:00
}
2022-08-12 22:53:46 +08:00
var nameOnly bool
func init() {
commandVersion.Flags().BoolVarP(&nameOnly, "name", "n", false, "print version name only")
2022-08-13 18:36:49 +08:00
mainCommand.AddCommand(commandVersion)
2022-08-12 22:53:46 +08:00
}
2022-07-04 17:08:28 +08:00
func printVersion(cmd *cobra.Command, args []string) {
2022-08-12 22:53:46 +08:00
var version string
if !nameOnly {
version = "sing-box "
}
version += F.ToString(C.Version)
if C.Commit != "" {
version += "." + C.Commit
}
if !nameOnly {
version += " ("
version += runtime.Version()
version += ", "
version += runtime.GOOS
version += ", "
version += runtime.GOARCH
version += ", "
version += "CGO "
if C.CGO_ENABLED {
version += "enabled"
} else {
version += "disabled"
}
version += ")"
2022-08-12 15:46:26 +08:00
}
2022-08-12 22:53:46 +08:00
version += "\n"
os.Stdout.WriteString(version)
2022-07-04 17:08:28 +08:00
}