Lots of previous answers (including the top one on google) are only applicable to older macOS, referencing old software that is no longer available or signed. I can't answer old questions since they are now locked. The top answer also doesn't refer to the CLI version.
The rar case is special because p7zip from homebrew doesn't work with rar.
https://theunarchiver.com/ is well known but afaik it's GUI only. I want to be able to automate extraction.
This post will apply to modern macOS, including Apple Silicon and ARM64.