From 23cc07dd1655df05f6967ce848169ab4c658e707 Mon Sep 17 00:00:00 2001 From: Adrien Hopkins Date: Fri, 15 Sep 2023 10:19:26 -0500 Subject: Forbid -d when digit map cannot be shown -d shows only the digit map and nothing else, so if the digit map cannot be shown (e.g. radices above 36 without -f), it makes sense to forbid this rather than print an empty string. --- args.go | 2 ++ print_digit_map.go | 4 +--- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/args.go b/args.go index fbb4cf0..0fb12d4 100644 --- a/args.go +++ b/args.go @@ -61,6 +61,8 @@ func parseArgs() (args, error) { return args{}, uintParsingError(flag.Arg(0), err) } else if radix < 2 { return args{}, errors.New("Cannot use 0 or 1 as radices.") + } else if radix > maxSmallRadix && a.DigitMapOnly && !a.FullMap { + return args{}, errors.New("Used -d option, but digit map cannot be shown.") } a.Radix = uint(radix) diff --git a/print_digit_map.go b/print_digit_map.go index 1f5ad64..3e59c8c 100644 --- a/print_digit_map.go +++ b/print_digit_map.go @@ -12,9 +12,7 @@ import ( const maxSmallRadix = 36 func writeDigitMap(w io.Writer, digitMap []factors.DigitType) { - if len(digitMap) < 2 { - panic("Radices cannot be less than 2!") - } else if len(digitMap) <= 36 { + if len(digitMap) <= 36 { writeDigitMapSmall(w, digitMap) } } -- cgit v1.2.3