I had to look for a while before finding out how to easily connect to a wifi network via the command line. Here is a set of three commands to connect to a network and set it to autoconnect. The first command is only used to make sure that the network does not already exist.

nmcli con delete YOUR_NETWORK_SSID
nmcli device wifi connect "YOUR_NETWORK_SSID" password "YOUR_NETWORK_PASSWORD"
nmcli connection modify "YOUR_NETWORK_SSID" connection.autoconnect yes