hostSync/main.go

57 lines
1.3 KiB
Go
Raw Blame History

This file contains ambiguous Unicode characters

This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

package main
import (
"fmt"
"os"
"strings"
"github.com/evil7/hostsync/cmd"
"github.com/evil7/hostsync/config"
"github.com/evil7/hostsync/utils"
)
func main() {
// 只在版本命令时显示banner
if isVersionCommand() {
showBanner()
}
// 初始化配置
config.Init()
// 初始化日志系统
if err := utils.InitLogger(); err != nil {
// 日志系统初始化失败时直接输出到stderr不使用日志系统
fmt.Fprintf(os.Stderr, "警告: 初始化日志系统失败: %v\n", err)
}
defer utils.CloseLogger()
// 记录用户完整的命令输入(排除程序名,只记录有意义的命令)
if len(os.Args) > 1 && !isVersionCommand() {
commandLine := strings.Join(os.Args[1:], " ")
utils.LogFileOnly("用户执行: %s", commandLine)
}
// 执行命令
cmd.Execute()
}
// isVersionCommand 检查是否是版本命令
func isVersionCommand() bool {
if len(os.Args) < 2 {
return false
}
arg := os.Args[1]
return arg == "version" || arg == "--version" || arg == "-v"
}
func showBanner() {
banner := `
_ _
| |__ ___ ___| |_ ___ _ _ _ __ ___
| '_ \ / _ \/ __| __/ __| | | | '_ \ / __|
| | | | (_) \__ \ |_\__ \ |_| | | | | (__
|_| |_|\___/|___/\__|___/\__, |_| |_|\___|
by evil7@deepwn |___/
`
fmt.Println(banner)
}