I get those in bed from time to time and my course of action is to keep the leg strait during the onset, get out of bed and stand up stretching the leg muscle. The pain can be very intense but once I stand up and apply pressure by standing on the leg, it almost immediately stops the cramp and the pain subsides within a few seconds.
I used to let the leg contract and curl up powering through the cramp pain until it subsided but a few times it lasted over a minute which is agonizing.