Move the CLI stuff into a single method.