wip7
This commit is contained in:
@@ -0,0 +1,59 @@
|
||||
/*
|
||||
* Copyright (c) 2025-2026, Антон Аксенов
|
||||
* This file is part of iptvc project
|
||||
* MIT License: https://git.axenov.dev/IPTV/iptvc/src/branch/master/LICENSE
|
||||
*/
|
||||
|
||||
package cmd
|
||||
|
||||
import (
|
||||
"axenov/iptv-checker/app"
|
||||
"axenov/iptv-checker/app/web"
|
||||
|
||||
"github.com/spf13/cobra"
|
||||
)
|
||||
|
||||
// serveCmd represents the serve command
|
||||
var serveCmd = &cobra.Command{
|
||||
Use: "serve",
|
||||
Short: "Start web interface",
|
||||
Long: `Start web interface for browsing IPTV playlists.
|
||||
Use --check to enable background playlist checking.
|
||||
Copyright (c) 2025, Антон Аксенов, MIT license.`,
|
||||
Run: func(cmd *cobra.Command, args []string) {
|
||||
app.Init()
|
||||
applyAppOverrides(cmd)
|
||||
applyCacheOverrides(cmd)
|
||||
applyCheckOverrides(cmd)
|
||||
app.InitCache()
|
||||
|
||||
// CLI-флаги переопределяют конфиг, только если заданы явно.
|
||||
if cmd.Flags().Changed("port") {
|
||||
app.Config.Server.Port = app.Args.ServerPort
|
||||
}
|
||||
if cmd.Flags().Changed("host") {
|
||||
app.Config.Server.Host = app.Args.ServerHost
|
||||
}
|
||||
|
||||
server := web.NewServer(app.Config, app.Cache)
|
||||
|
||||
// запускаем фоновую проверку, если передан --check или включён check.start-on-serve в конфиге
|
||||
if app.Args.NeedCheck || app.Config.Check.StartOnServe {
|
||||
opts := web.CheckOptions{
|
||||
Repeat: app.Args.RepeatCount,
|
||||
Random: app.Args.RandomCount,
|
||||
}
|
||||
go server.StartBackgroundChecker(opts)
|
||||
}
|
||||
|
||||
server.Start()
|
||||
},
|
||||
}
|
||||
|
||||
func init() {
|
||||
serveCmd.Flags().UintVarP(&app.Args.ServerPort, "port", "p", 0, "port for web interface (overrides config.yml and env)")
|
||||
serveCmd.Flags().StringVar(&app.Args.ServerHost, "host", "", "host to bind web interface (overrides config.yml and env)")
|
||||
serveCmd.Flags().BoolVar(&app.Args.NeedCheck, "check", false, "enable background playlist checking")
|
||||
addCommonCheckFlags(serveCmd, 0)
|
||||
rootCmd.AddCommand(serveCmd)
|
||||
}
|
||||
Reference in New Issue
Block a user