| 4039 | } |
| 4040 | |
| 4041 | func parseGitMirrorOptions(ctx *snap.Context, start int) (gitMirrorOptions, error) { |
| 4042 | opts := gitMirrorOptions{} |
| 4043 | for i := start; i < ctx.NArgs(); i++ { |
| 4044 | arg := strings.TrimSpace(ctx.Arg(i)) |
| 4045 | if arg == "" { |
| 4046 | continue |
| 4047 | } |
| 4048 | |
| 4049 | switch { |
| 4050 | case arg == "--remote": |
| 4051 | i++ |
| 4052 | if i >= ctx.NArgs() { |
| 4053 | return opts, fmt.Errorf("--remote requires a value") |
| 4054 | } |
| 4055 | opts.remote = strings.TrimSpace(ctx.Arg(i)) |
| 4056 | case strings.HasPrefix(arg, "--remote="): |
| 4057 | opts.remote = strings.TrimSpace(strings.TrimPrefix(arg, "--remote=")) |
| 4058 | case arg == "--branch": |
| 4059 | i++ |
| 4060 | if i >= ctx.NArgs() { |
| 4061 | return opts, fmt.Errorf("--branch requires a value") |
| 4062 | } |
| 4063 | opts.branch = strings.TrimSpace(ctx.Arg(i)) |
| 4064 | case strings.HasPrefix(arg, "--branch="): |
| 4065 | opts.branch = strings.TrimSpace(strings.TrimPrefix(arg, "--branch=")) |
| 4066 | case arg == "--url": |
| 4067 | i++ |
| 4068 | if i >= ctx.NArgs() { |
| 4069 | return opts, fmt.Errorf("--url requires a value") |
| 4070 | } |
| 4071 | opts.url = strings.TrimSpace(ctx.Arg(i)) |
| 4072 | case strings.HasPrefix(arg, "--url="): |
| 4073 | opts.url = strings.TrimSpace(strings.TrimPrefix(arg, "--url=")) |
| 4074 | case arg == "--strategy": |
| 4075 | i++ |
| 4076 | if i >= ctx.NArgs() { |
| 4077 | return opts, fmt.Errorf("--strategy requires a value") |
| 4078 | } |
| 4079 | opts.strategy = strings.TrimSpace(ctx.Arg(i)) |
| 4080 | case strings.HasPrefix(arg, "--strategy="): |
| 4081 | opts.strategy = strings.TrimSpace(strings.TrimPrefix(arg, "--strategy=")) |
| 4082 | case strings.HasPrefix(arg, "--"): |
| 4083 | return opts, fmt.Errorf("unknown flag %q", arg) |
| 4084 | default: |
| 4085 | if opts.branch == "" { |
| 4086 | opts.branch = arg |
| 4087 | continue |
| 4088 | } |
| 4089 | return opts, fmt.Errorf("unexpected argument %q", arg) |
| 4090 | } |
| 4091 | } |
| 4092 | return opts, nil |
| 4093 | } |
| 4094 | |
| 4095 | func runGitMirrorSetup(ctx *snap.Context, opts gitMirrorOptions) error { |
| 4096 | remote := strings.TrimSpace(opts.remote) |