I wrote this a while back to document managing WIFI connections using the command line.
https://www.mattcrampton.com/blog/managing_wifi_connections_...
I use these commands a lot when I'm in a coffeeshop and I'm trying to fine-grain control which wifi connection my laptop is using and dealing with passwords.
IMO OSX's UI for wifi network picking is clunky when you're in an area with >50 wifi networks in range, command line tools are much easier to deal with.