Its own module not in cligen/argcvt since it's POSIX/Unix-only & few utils need it; Can be a nice UX for those who expect it.
While a new Nim type enum UnixSignal = sigHup = (SIGHUP, "HUP"), ... with a new kill wrapper would be cleaner, for CL utils there is ancient tradition of just knowing & using signal numbers like "9".
Meanwhile, for almost any other notional enum, users would NOT be expected to know "9". So, a new "integer literal alternate" for all enums (or a Hex spelling for setenum!) seems of dubious value.
The compromise here is to just use strings for CLs but also accept numbers. While we are at it, go fully case-insensitive since "hup" or "int" are easier to keystroke, introduce SysV CLD alias & "SIGNIL=0" & also accept an optional "sig" prefix allowing CLusers to be more explicit, e.g. in shell scripts.
This may all seem like over-optimizing for CLuser expectations vs prog.lang. coherence, but whether in procs find -akill aka pk or elsewise, sending signals often coincides with rogue processes which can induce CLuser-level panic when people have the least patience with expectations being unmet.
This code had been in procs.nim, but make sense here since there can be other reasons why a user might want a signal in a CLI, like bu/etr aborts.
Lets
signum = toCritBitTree([("NIL", cint(0)), ("HUP", 1'i32), ("INT", 2'i32), ("QUIT", 3'i32), ("ILL", 4'i32), ("TRAP", 5'i32), ("ABRT", 6'i32), ("BUS", 7'i32), ("FPE", 8'i32), ("KILL", 9'i32), ("USR1", 10'i32), ("SEGV", 11'i32), ("USR2", 12'i32), ("PIPE", 13'i32), ("ALRM", 14'i32), ("TERM", 15'i32), ("TKFLT", cint(16)), ("CHLD", 17'i32), ("CLD", 17'i32), ("CONT", 18'i32), ("STOP", 19'i32), ("TSTP", 20'i32), ("TTIN", 21'i32), ("TTOU", 22'i32), ("URG", 23'i32), ("XCPU", 24'i32), ("XFSZ", 25'i32), ("VTALRM", 26'i32), ("PROF", 27'i32), ("WINCH", cint(28)), ("POLL", 29'i32), ("PWR", cint(30)), ("SYS", 31'i32), ("UNUSED", cint(31))])
Procs
proc parseUnixSignal(nameOrNumber: string): cint {. ...raises: [ValueError, KeyError, IOError], tags: [WriteIOEffect], forbids: [].}
- Accepts numbers as-is & otherwise case-insensitively prefix-matches against a set of standard signal abbreviations with an optional "SIG" prefix.