Refactor step 2: Moved up some CLI common parts.