-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcmd_sync.go
More file actions
53 lines (42 loc) · 1.08 KB
/
cmd_sync.go
File metadata and controls
53 lines (42 loc) · 1.08 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
package main
import (
"context"
"fmt"
"github.com/urfave/cli/v3"
)
func newSyncCommand() *cli.Command {
return &cli.Command{
Name: "sync",
Usage: "Synchronize anime/manga lists between services",
Flags: syncFlags,
Action: runSync,
}
}
func runSync(ctx context.Context, cmd *cli.Command) error {
configPath := cmd.String("config")
// Set package-level vars for compatibility with existing code
verboseVal, reverseVal := getSyncFlagsFromCmd(cmd)
// Initialize logger and add to context
logger := NewLogger(verboseVal)
ctx = logger.WithContext(ctx)
var direction SyncDirection
if reverseVal {
direction = SyncDirectionReverse
} else {
direction = SyncDirectionForward
}
ctx = WithDirection(ctx, direction)
config, err := loadConfigFromFile(configPath)
if err != nil {
return fmt.Errorf("error loading config: %w", err)
}
applySyncFlagsToConfig(cmd, &config)
app, err := NewApp(ctx, config, reverseVal)
if err != nil {
return fmt.Errorf("create app: %w", err)
}
if err := app.Run(ctx); err != nil {
return fmt.Errorf("run app: %w", err)
}
return nil
}