Every person committed, detained, confined or restrained of his liberty, within this state, for any criminal or supposed criminal matter, or under any pretense whatsoever, except when, according to the provisions of this chapter, such person can be neither discharged nor bailed, or otherwise relieved, may prosecute a writ of habeas corpus as herein provided, to inquire into the cause of such confinement or restraint.
§ 532.010, RSMo