How can I toggle Automatic Graphics Switching using terminal?
The command sudo pmset -a gpuswitch n will set the graphics switching, with the following values for n:


2 is integrated gpu both on cable and battery 
1 is dedicated gpu only with power connected; integrated gpu on battery power
0 is dedicated gpu on both ac and battery


pmset -g will show you the current configuration.