This commit is contained in:
Rogee
2024-09-04 17:37:43 +08:00
parent 843355f4a0
commit c34547a3f1
6 changed files with 19 additions and 14 deletions

View File

@@ -83,7 +83,7 @@ func (t *TClient) Channel(ctx context.Context, channel *tg.Channel, cfg *DBChann
zap.Int64("size", doc.GetSize()), zap.Int64("size", doc.GetSize()),
zap.String("SizeHuman", humanize.Bytes(uint64(doc.GetSize()))), zap.String("SizeHuman", humanize.Bytes(uint64(doc.GetSize()))),
) )
continue break
} }
data, err := t.saveDocument(ctx, cfg, doc) data, err := t.saveDocument(ctx, cfg, doc)

View File

@@ -2,7 +2,7 @@ package internal
import ( import (
"context" "context"
"fmt" "log"
"exporter/config" "exporter/config"
@@ -22,8 +22,8 @@ func ExportCmd() *cobra.Command {
Use: "export", Use: "export",
Short: "export channels", Short: "export channels",
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client") log.Println("init client")
defer fmt.Println("init client done") defer log.Println("init client done")
return InitClient(config.C) return InitClient(config.C)
}, },
RunE: wrapE(exportCmd), RunE: wrapE(exportCmd),

View File

@@ -2,7 +2,7 @@ package internal
import ( import (
"context" "context"
"fmt" "log"
"exporter/config" "exporter/config"
@@ -14,8 +14,8 @@ func LoginCmd() *cobra.Command {
Use: "login", Use: "login",
Short: "login account", Short: "login account",
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client") log.Println("init client")
defer fmt.Println("init client done") defer log.Println("init client done")
return InitClient(config.C) return InitClient(config.C)
}, },
RunE: wrapE(func(ctx context.Context) error { RunE: wrapE(func(ctx context.Context) error {

View File

@@ -2,7 +2,7 @@ package internal
import ( import (
"context" "context"
"fmt" "log"
"time" "time"
"exporter/config" "exporter/config"
@@ -20,8 +20,8 @@ func WatchCmd() *cobra.Command {
Use: "watch", Use: "watch",
Short: "watch channels", Short: "watch channels",
PreRunE: func(cmd *cobra.Command, args []string) error { PreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("init client") log.Println("init client")
defer fmt.Println("init client done") defer log.Println("init client done")
return InitClient(config.C) return InitClient(config.C)
}, },
RunE: wrapE(watchCmd), RunE: wrapE(watchCmd),

View File

@@ -2,6 +2,7 @@ package internal
import ( import (
"context" "context"
"log"
"exporter/config" "exporter/config"
@@ -49,6 +50,8 @@ func getClient() *TClient {
func wrapE(f func(context.Context) error) func(cmd *cobra.Command, args []string) error { func wrapE(f func(context.Context) error) func(cmd *cobra.Command, args []string) error {
return func(cmd *cobra.Command, args []string) error { return func(cmd *cobra.Command, args []string) error {
log.Println("run client")
defer log.Println("run client done")
return getClient().Client.Run(context.Background(), f) return getClient().Client.Run(context.Background(), f)
} }
} }

10
main.go
View File

@@ -1,7 +1,7 @@
package main package main
import ( import (
"fmt" "log"
"os" "os"
"exporter/config" "exporter/config"
@@ -18,19 +18,19 @@ func main() {
Use: "exporter", Use: "exporter",
Short: "Yet Another Telegram Channel Exporter", Short: "Yet Another Telegram Channel Exporter",
PersistentPreRunE: func(cmd *cobra.Command, args []string) error { PersistentPreRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("load configs") log.Println("load configs")
if err := config.Load(cfgFile); err != nil { if err := config.Load(cfgFile); err != nil {
return errors.Wrap(err, "load config") return errors.Wrap(err, "load config")
} }
fmt.Println("init db") log.Println("init db")
if err := internal.InitDB(config.C.DSN); err != nil { if err := internal.InitDB(config.C.DSN); err != nil {
return errors.Wrap(err, "init db") return errors.Wrap(err, "init db")
} }
return nil return nil
}, },
PersistentPostRunE: func(cmd *cobra.Command, args []string) error { PersistentPostRunE: func(cmd *cobra.Command, args []string) error {
fmt.Println("client exit") log.Println("client exit")
return internal.Close() return internal.Close()
}, },
} }
@@ -45,6 +45,7 @@ func main() {
// rootCmd.SilenceErrors = true // rootCmd.SilenceErrors = true
rootCmd.SilenceUsage = true rootCmd.SilenceUsage = true
rootCmd.SilenceErrors = true
rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error { rootCmd.SetFlagErrorFunc(func(cmd *cobra.Command, err error) error {
cmd.Println(err) cmd.Println(err)
cmd.Println(cmd.UsageString()) cmd.Println(cmd.UsageString())
@@ -53,6 +54,7 @@ func main() {
err := rootCmd.Execute() err := rootCmd.Execute()
if err != nil { if err != nil {
log.Println(err)
os.Exit(1) os.Exit(1)
} }
} }