Improved usage of exit codes in CLI commands

Some CLI commands print error/warning messages to the console in case of failure, and exit with a zero exit code. This commit fixes that, so all CLI commands exit with non-zero exit code whenever the operation was not succesfully performed.

The commit includes some light cleaning in api operations