de-duplicate command parsing code