(name, short string, dryRun bool, defaultMode gitsync.OperationMode)
| 23 | } |
| 24 | |
| 25 | func newSyncLikeCmd(name, short string, dryRun bool, defaultMode gitsync.OperationMode) *cobra.Command { |
| 26 | var ( |
| 27 | mappings []string |
| 28 | jsonOutput bool |
| 29 | sourceAuth gitsync.EndpointAuth |
| 30 | targetAuth gitsync.EndpointAuth |
| 31 | branches string |
| 32 | modeValue = operationModeFlag(defaultOperationMode(defaultMode)) |
| 33 | protocolVal = newProtocolFlag() |
| 34 | legacyForce bool |
| 35 | req = unstable.SyncRequest{DryRun: dryRun} |
| 36 | ) |
| 37 | |
| 38 | cmd := &cobra.Command{ |
| 39 | Use: name + " [flags] <source-url> <target-url>", |
| 40 | Short: short, |
| 41 | Args: cobra.MaximumNArgs(2), |
| 42 | SilenceErrors: true, |
| 43 | SilenceUsage: true, |
| 44 | RunE: func(cmd *cobra.Command, args []string) error { |
| 45 | if legacyForce { |
| 46 | return errors.New("--force has been removed; use --force-with-lease (previous semantics) or --force-blind (real overwrite)") |
| 47 | } |
| 48 | req.Policy.Mode = gitsync.OperationMode(modeValue) |
| 49 | req.Policy.Protocol = gitsync.ProtocolMode(protocolVal) |
| 50 | |
| 51 | if req.Source.URL == "" && len(args) > 0 { |
| 52 | req.Source.URL = args[0] |
| 53 | } |
| 54 | if req.Target.URL == "" && len(args) > 1 { |
| 55 | req.Target.URL = args[1] |
| 56 | } |
| 57 | |
| 58 | if branches != "" { |
| 59 | req.Scope.Branches = splitCSV(branches) |
| 60 | } |
| 61 | for _, raw := range mappings { |
| 62 | mapping, err := validation.ParseMapping(raw) |
| 63 | if err != nil { |
| 64 | return fmt.Errorf("parse mapping %q: %w", raw, err) |
| 65 | } |
| 66 | req.Scope.Mappings = append(req.Scope.Mappings, gitsync.RefMapping{ |
| 67 | Source: mapping.Source, |
| 68 | Target: mapping.Target, |
| 69 | }) |
| 70 | } |
| 71 | |
| 72 | if req.Source.URL == "" || req.Target.URL == "" { |
| 73 | return fmt.Errorf("%s requires source and target repository URLs", name) |
| 74 | } |
| 75 | |
| 76 | client := unstable.New(unstable.Options{ |
| 77 | Auth: gitsync.StaticAuthProvider{Source: sourceAuth, Target: targetAuth}, |
| 78 | }) |
| 79 | |
| 80 | var ( |
| 81 | result unstable.Result |
| 82 | err error |
no test coverage detected