| 52 | } |
| 53 | |
| 54 | func runSync(_ *cobra.Command, _ []string) error { |
| 55 | flags := GetGlobalFlags() |
| 56 | |
| 57 | switch syncConflict { |
| 58 | case sync.ConflictSkip, sync.ConflictRemote, sync.ConflictLocal: |
| 59 | default: |
| 60 | return fmt.Errorf("invalid --conflict value %q: must be skip, remote, or local", syncConflict) |
| 61 | } |
| 62 | |
| 63 | cfg, err := sync.LoadConfig(".") |
| 64 | if err != nil { |
| 65 | return err |
| 66 | } |
| 67 | |
| 68 | engine := &sync.Engine{ |
| 69 | ConfigDir: ".", |
| 70 | Verbose: flags.Verbose, |
| 71 | DryRun: syncDryRun, |
| 72 | ConflictStrategy: syncConflict, |
| 73 | } |
| 74 | |
| 75 | sources := cfg.Sources |
| 76 | if syncSource != "" { |
| 77 | sources = filterSources(cfg.Sources, syncSource) |
| 78 | if len(sources) == 0 { |
| 79 | return fmt.Errorf("source %q not found in config", syncSource) |
| 80 | } |
| 81 | } |
| 82 | |
| 83 | for _, srcCfg := range sources { |
| 84 | if !flags.Quiet { |
| 85 | fmt.Fprintf(os.Stderr, "Syncing from %s...\n", srcCfg.Name) |
| 86 | } |
| 87 | |
| 88 | result, err := engine.RunSync(srcCfg) |
| 89 | if err != nil { |
| 90 | return fmt.Errorf("sync failed for %s: %w", srcCfg.Name, err) |
| 91 | } |
| 92 | |
| 93 | printSyncResult(srcCfg.Name, result, flags.Quiet) |
| 94 | } |
| 95 | |
| 96 | return nil |
| 97 | } |
| 98 | |
| 99 | func filterSources(sources []sync.SourceConfig, name string) []sync.SourceConfig { |
| 100 | for _, s := range sources { |