mirror of
https://github.com/wyx2685/V2bX.git
synced 2025-01-23 02:18:13 -05:00
39 lines
844 B
Go
39 lines
844 B
Go
|
package cmd
|
||
|
|
||
|
import (
|
||
|
"fmt"
|
||
|
"github.com/beevik/ntp"
|
||
|
"github.com/sagernet/sing-box/common/settings"
|
||
|
"github.com/spf13/cobra"
|
||
|
)
|
||
|
|
||
|
var ntpServer string
|
||
|
|
||
|
var commandSyncTime = &cobra.Command{
|
||
|
Use: "synctime",
|
||
|
Short: "Sync time from ntp server",
|
||
|
Args: cobra.NoArgs,
|
||
|
Run: synctimeHandle,
|
||
|
}
|
||
|
|
||
|
func init() {
|
||
|
commandSyncTime.Flags().StringVar(&ntpServer, "server", "time.apple.com", "ntp server")
|
||
|
command.AddCommand(commandSyncTime)
|
||
|
}
|
||
|
|
||
|
func synctimeHandle(_ *cobra.Command, _ []string) {
|
||
|
t, err := ntp.Time(ntpServer)
|
||
|
if err != nil {
|
||
|
fmt.Println(Err("get time from server error: ", err))
|
||
|
fmt.Println(Err("同步时间失败"))
|
||
|
return
|
||
|
}
|
||
|
err = settings.SetSystemTime(t)
|
||
|
if err != nil {
|
||
|
fmt.Println(Err("set system time error: ", err))
|
||
|
fmt.Println(Err("同步时间失败"))
|
||
|
return
|
||
|
}
|
||
|
fmt.Println(Ok("同步时间成功"))
|
||
|
}
|