(opts Options)
| 27 | } |
| 28 | |
| 29 | func Run(opts Options) ([]SourceResult, error) { |
| 30 | cfg, err := config.Load(opts.ConfigPath) |
| 31 | if err != nil { |
| 32 | return nil, err |
| 33 | } |
| 34 | |
| 35 | selected := make([]config.Source, 0, len(cfg.Sources)) |
| 36 | for _, s := range cfg.Sources { |
| 37 | if opts.SourceName == "" || s.Name == opts.SourceName { |
| 38 | selected = append(selected, s) |
| 39 | } |
| 40 | } |
| 41 | if len(selected) == 0 { |
| 42 | return nil, fmt.Errorf("no sources matched %q", opts.SourceName) |
| 43 | } |
| 44 | |
| 45 | if err := os.MkdirAll("sources", 0o755); err != nil { |
| 46 | return nil, fmt.Errorf("create sources dir: %w", err) |
| 47 | } |
| 48 | |
| 49 | results := make([]SourceResult, 0, len(selected)) |
| 50 | for _, src := range selected { |
| 51 | r, err := syncSource(src, opts.DryRun) |
| 52 | if err != nil { |
| 53 | return nil, err |
| 54 | } |
| 55 | results = append(results, r) |
| 56 | } |
| 57 | |
| 58 | if !opts.DryRun { |
| 59 | if err := writeLock(results, cfg); err != nil { |
| 60 | return nil, err |
| 61 | } |
| 62 | } |
| 63 | |
| 64 | return results, nil |
| 65 | } |
| 66 | |
| 67 | func syncSource(src config.Source, dryRun bool) (SourceResult, error) { |
| 68 | repoDir := filepath.Join("sources", src.Name) |
no test coverage detected