MCPcopy Create free account
hub / github.com/alibaba/open-code-review / parseDelegateFlags

Function parseDelegateFlags

cmd/opencodereview/delegate_cmd.go:46–89  ·  view source on GitHub ↗
(args []string)

Source from the content-addressed store, hash-verified

44}
45
46func parseDelegateFlags(args []string) (delegateOptions, []string, error) {
47 a := newOcrFlagSet("ocr delegate")
48
49 opts := delegateOptions{}
50 a.StringVar(&opts.repoDir, "repo", "", "root directory of the git repository (default: current dir)")
51 a.StringVar(&opts.from, "from", "", "source ref to start diff from (e.g., 'main')")
52 a.StringVar(&opts.to, "to", "", "target ref to end diff at (e.g., 'feature-branch')")
53 a.StringVarP(&opts.commit, "commit", "c", "", "single commit hash or tag to review (vs its parent)")
54 a.StringVar(&opts.excludes, "exclude", "", "comma-separated gitignore-style patterns to exclude")
55 a.StringVar(&opts.rulePath, "rule", "", "path to JSON file with system review rules")
56 a.StringVarP(&opts.background, "background", "b", "", "optional requirement/business context")
57 a.StringVarP(&opts.backgroundFile, "background-file", "B", "", "path to a Markdown file used as background")
58 a.IntVar(&opts.maxGitProcs, "max-git-procs", 16, "max concurrent git subprocesses")
59
60 if err := a.Parse(args); err != nil {
61 return opts, nil, fmt.Errorf("parse flags: %w", err)
62 }
63
64 opts.showHelp = a.showHelp
65 if opts.showHelp {
66 return opts, nil, nil
67 }
68
69 // Validate mode exclusivity
70 modeCount := 0
71 if opts.from != "" || opts.to != "" {
72 modeCount++
73 }
74 if opts.commit != "" {
75 modeCount++
76 }
77 if modeCount > 1 {
78 return opts, nil, fmt.Errorf("only one review mode allowed (--from/--to or --commit)")
79 }
80 if opts.from != "" && opts.to == "" {
81 return opts, nil, fmt.Errorf("--to is required when --from is specified")
82 }
83 if opts.to != "" && opts.from == "" {
84 return opts, nil, fmt.Errorf("--from is required when --to is specified")
85 }
86
87 remaining := a.fs.Args()
88 return opts, remaining, nil
89}
90
91// delegateContext holds the shared state for delegate sub-commands.
92type delegateContext struct {

Callers 2

runDelegatePreviewFunction · 0.85
runDelegateRuleFunction · 0.85

Calls 5

newOcrFlagSetFunction · 0.85
StringVarMethod · 0.80
StringVarPMethod · 0.80
IntVarMethod · 0.80
ParseMethod · 0.80

Tested by

no test coverage detected