Factor out shared code from gear command