Extract output functions from cli.py, reorganize.