cyclo over 15
Dependencies
- [2]
YE6BZJUKtidy up lat lng timezone api for calls clip cmd - [3]
BZ6KQRYDadded complexity lint test - [4]
2P27XV3Dfixed cyclo over 30 - [5]
YUIQQPXYremoved --wav-only from calls clip cmd - [6]
KZKLAINJrun out of space on nest, cleaned out - [7]
NS4TDPLNcyclomatic complexity - [8]
GVOVKH5Rmore cyclo refactoring
Change contents
- replacement in lint_test.go at line 48
cmd := exec.Command("gocyclo", "-over", "18", ".")cmd := exec.Command("gocyclo", "-over", "15", ".") - edit in cmd/calls_clip.go at line 5
"flag" - edit in cmd/calls_clip.go at line 8
"strconv""strings" - edit in cmd/calls_clip.go at line 11
// clipArgParser holds state for parsing CLI arguments incrementally.type clipArgParser struct {args []stringi int}// nextValue returns the next argument after the current flag, or exits with an error.func (p *clipArgParser) nextValue(flag string) string {if p.i+1 >= len(p.args) {fmt.Fprintf(os.Stderr, "Error: %s requires a value\n", flag)os.Exit(1)}v := p.args[p.i+1]p.i += 2return v}// nextInt parses the next argument as an integer, or exits with an error.func (p *clipArgParser) nextInt(flag string) int {s := p.nextValue(flag)v, err := strconv.Atoi(s)if err != nil {fmt.Fprintf(os.Stderr, "Error: %s must be an integer\n", flag)os.Exit(1)}return v} - edit in cmd/calls_clip.go at line 12
// nextUniqueValue returns the next argument after the flag, or exits if already set.func (p *clipArgParser) nextUniqueValue(flag, current string) string {if current != "" {fmt.Fprintf(os.Stderr, "Error: %s can only be specified once\n", flag)os.Exit(1)}return p.nextValue(flag)} - replacement in cmd/calls_clip.go at line 61
// parseClipArgs parses CLI arguments into clip flags// parseClipArgs parses CLI arguments into clip flags using flag.FlagSet. - replacement in cmd/calls_clip.go at line 63[4.27532]→[4.27532:27563](∅→∅),[4.27563]→[4.16069:16144](∅→∅),[4.1137119]→[4.16069:16144](∅→∅),[4.1137166]→[4.1137166:1137198](∅→∅),[4.1137198]→[4.27564:27593](∅→∅),[4.16172]→[4.1137337:1137356](∅→∅),[4.27593]→[4.1137337:1137356](∅→∅),[4.1137337]→[4.1137337:1137356](∅→∅),[4.1137356]→[4.27594:27625](∅→∅),[4.16202]→[4.1137499:1137518](∅→∅),[4.27625]→[4.1137499:1137518](∅→∅),[4.1137499]→[4.1137499:1137518](∅→∅),[4.1137518]→[4.27626:27657](∅→∅),[4.16232]→[4.1137661:1137680](∅→∅),[4.27657]→[4.1137661:1137680](∅→∅),[4.1137661]→[4.1137661:1137680](∅→∅),[4.1137680]→[4.27658:27689](∅→∅),[4.16262]→[4.1137823:1137842](∅→∅),[4.27689]→[4.1137823:1137842](∅→∅),[4.1137823]→[4.1137823:1137842](∅→∅),[4.1137842]→[4.27690:27737](∅→∅),[4.16292]→[4.1138101:1138121](∅→∅),[4.27737]→[4.1138101:1138121](∅→∅),[4.1138101]→[4.1138101:1138121](∅→∅),[4.1138121]→[4.27738:27787](∅→∅),[4.16323]→[4.1138384:1138406](∅→∅),[4.27787]→[4.1138384:1138406](∅→∅),[4.1138384]→[4.1138384:1138406](∅→∅),[4.1138406]→[4.16324:16347](∅→∅),[4.16347]→[4.1138665:1138787](∅→∅),[4.1138665]→[4.1138665:1138787](∅→∅),[4.1138787]→[4.27788:27807](∅→∅),[4.27807]→[4.1138815:1138832](∅→∅),[4.1138815]→[4.1138815:1138832](∅→∅),[4.1138832]→[4.27808:27835](∅→∅),[4.16373]→[4.1139104:1139122](∅→∅),[4.27835]→[4.1139104:1139122](∅→∅),[4.1139104]→[4.1139104:1139122](∅→∅),[4.1139122]→[4.27836:27854](∅→∅),[4.27875]→[4.16384:16393](∅→∅),[4.1139185]→[4.16384:16393](∅→∅),[4.16393]→[4.1139193:1139211](∅→∅),[4.1139193]→[4.1139193:1139211](∅→∅),[4.1139211]→[4.27876:27894](∅→∅),[4.27894]→[4.16394:16403](∅→∅),[4.1139227]→[4.16394:16403](∅→∅),[4.16403]→[4.1139235:1139251](∅→∅),[4.1139235]→[4.1139235:1139251](∅→∅),[4.1139251]→[4.27895:27911](∅→∅),[4.27911]→[4.16404:16413](∅→∅),[4.1139265]→[4.16404:16413](∅→∅),[4.16413]→[2.3048:3120](∅→∅),[2.3120]→[4.1140061:1140118](∅→∅),[4.16499]→[4.1140061:1140118](∅→∅),[4.28041]→[4.1140061:1140118](∅→∅),[4.1140061]→[4.1140061:1140118](∅→∅),[4.1140119]→[4.1140119:1140130](∅→∅),[4.1140160]→[4.1140160:1140301](∅→∅),[4.1140301]→[4.16500:16509](∅→∅),[4.16509]→[4.1140308:1140312](∅→∅),[4.1140308]→[4.1140308:1140312](∅→∅)
f := clipFlags{certainty: -1}p := &clipArgParser{args: args}for p.i < len(args) {arg := args[p.i]switch arg {case "--file":f.file = p.nextValue(arg)case "--folder":f.folder = p.nextValue(arg)case "--output":f.output = p.nextValue(arg)case "--prefix":f.prefix = p.nextValue(arg)case "--filter":f.filter = p.nextUniqueValue(arg, f.filter)case "--species":f.species = p.nextUniqueValue(arg, f.species)case "--certainty":v := p.nextInt(arg)if v < 0 || v > 100 {fmt.Fprintf(os.Stderr, "Error: --certainty must be between 0 and 100\n")os.Exit(1)}f.certainty = vcase "--size":f.size = p.nextInt(arg)case "--color":f.color = truep.i++case "--night":f.night = truep.i++case "--day":f.day = truep.i++case "--location":f.location = p.nextUniqueValue(arg, f.location)case "-h", "--help":printClipUsage()os.Exit(0)default:if strings.HasPrefix(arg, "--") {fmt.Fprintf(os.Stderr, "Error: unknown flag: %s\n\n", arg)printClipUsage()os.Exit(1)}p.i++}fs := flag.NewFlagSet("calls clip", flag.ExitOnError)file := fs.String("file", "", "Path to .data file (required if no --folder)")folder := fs.String("folder", "", "Path to folder containing .data files (required if no --file)")output := fs.String("output", "", "Output folder for generated clips (required)")prefix := fs.String("prefix", "", "Prefix for output filenames (required)")filter := fs.String("filter", "", "Filter by ML model name")species := fs.String("species", "", "Filter by species, optionally with calltype")certainty := fs.Int("certainty", -1, "Filter by certainty value (0-100)")size := fs.Int("size", 0, "Spectrogram image size in pixels (224-896)")color := fs.Bool("color", false, "Apply L4 colormap to spectrogram")night := fs.Bool("night", false, "Only clip recordings made during solar night")day := fs.Bool("day", false, "Only clip recordings made during solar day")location := fs.String("location", "", "GPS coordinates and optional timezone")fs.Usage = printClipUsage_ = fs.Parse(args)if *certainty < -1 || *certainty > 100 {fmt.Fprintf(os.Stderr, "Error: --certainty must be between 0 and 100\n")os.Exit(1)}return clipFlags{file: *file,folder: *folder,output: *output,prefix: *prefix,filter: *filter,species: *species,size: *size,certainty: *certainty,color: *color,night: *night,day: *day,location: *location, - edit in cmd/calls_clip.go at line 99
return f