parseBlastRadiusArgs parses flags that may appear before or after the single optional positional path. Go's flag package stops at the first non-flag argument, so we re-parse the remainder after each positional to support position-independent flags (e.g. `blast-radius . --json`).
(fs *flag.FlagSet, args []string)
| 293 | // argument, so we re-parse the remainder after each positional to support |
| 294 | // position-independent flags (e.g. `blast-radius . --json`). |
| 295 | func parseBlastRadiusArgs(fs *flag.FlagSet, args []string) (string, error) { |
| 296 | var positionals []string |
| 297 | rest := args |
| 298 | for { |
| 299 | if err := fs.Parse(rest); err != nil { |
| 300 | return "", err |
| 301 | } |
| 302 | if fs.NArg() == 0 { |
| 303 | break |
| 304 | } |
| 305 | positionals = append(positionals, fs.Arg(0)) |
| 306 | rest = fs.Args()[1:] |
| 307 | } |
| 308 | if len(positionals) > 1 { |
| 309 | fmt.Fprintln(os.Stderr, "Usage: codemap blast-radius [--json|--markdown|--text] [--ref <base-ref>] [path]") |
| 310 | return "", fmt.Errorf("too many positional arguments") |
| 311 | } |
| 312 | root := "." |
| 313 | if len(positionals) == 1 { |
| 314 | root = positionals[0] |
| 315 | } |
| 316 | return root, nil |
| 317 | } |
| 318 | |
| 319 | // blastRadiusDiffError wraps a git-diff failure so the caller can surface the |
| 320 | // actionable "valid branch/ref" hint for a bad --ref. |
no outgoing calls
no test coverage detected