feat: add flag disable-timestamp; check empty node list after subscription resolving

This commit is contained in:
mzz2017
2023-02-04 22:02:37 +08:00
parent 5118a80bca
commit a6d2628505
4 changed files with 21 additions and 15 deletions

View File

@ -15,7 +15,8 @@ import (
)
var (
cfgFile string
cfgFile string
disableTimestamp bool
runCmd = &cobra.Command{
Use: "run",
@ -24,7 +25,9 @@ var (
if cfgFile == "" {
logrus.Fatalln("Argument \"--config\" or \"-c\" is required but not provided.")
}
if err := Run(); err != nil {
logrus.SetLevel(logrus.DebugLevel)
log := logger.NewLogger(2, disableTimestamp)
if err := Run(log); err != nil {
logrus.Fatalln(err)
}
},
@ -33,11 +36,10 @@ var (
func init() {
runCmd.PersistentFlags().StringVarP(&cfgFile, "config", "c", "", "config file")
runCmd.PersistentFlags().BoolVarP(&disableTimestamp, "disable-timestamp", "", false, "disable timestamp")
}
func Run() (err error) {
logrus.SetLevel(logrus.DebugLevel)
log := logger.NewLogger(2)
func Run(log *logrus.Logger) (err error) {
// Require "sudo" if necessary.
internal.AutoSu()
@ -58,6 +60,9 @@ func Run() (err error) {
}
nodeList = append(nodeList, nodes...)
}
if len(nodeList) == 0 {
return fmt.Errorf("no node found, which could because all subscription resolving failed")
}
if len(param.Global.LanInterface) == 0 && len(param.Global.WanInterface) == 0 {
return fmt.Errorf("LanInterface and WanInterface cannot both be empty")