robotfs/main.go
2025-05-12 20:23:33 +08:00

68 lines
1.1 KiB
Go

package main
import (
"flag"
"fmt"
"gosvc"
"os"
"robotfs/config"
"robotfs/utils"
)
const usage = `Usage: robotfs [options]
Options:
--config string Path to config file (required)
--version Show version information
--help Show this help message
Example:
robotfs --config=/path/to/config.yaml`
func printUsage() {
fmt.Println(usage)
}
func main() {
configFile := flag.String("config", "", "path to config file")
version := flag.Bool("version", false, "show version information")
help := flag.Bool("help", false, "show help message")
flag.Parse()
if *help {
printUsage()
return
}
if *version {
gosvc.Config.PrintVersion()
return
}
if *configFile != "" {
utils.ConfigurationFileDirectory.Set(*configFile)
if !utils.LoadConfiguration("config", true) {
os.Exit(1)
}
} else {
fmt.Println("Error: --config flag is required")
printUsage()
os.Exit(1)
}
config.SetupServiceConfig()
svc, err := CreateService()
if err != nil {
fmt.Println("create service failed, " + err.Error())
return
}
err = gosvc.Run(svc)
if err != nil {
fmt.Println("run service failed, " + err.Error())
return
}
}