This splits the logic into a cli, which handles parsing command line args and
reading files, and a terminal abstraction for handling user input and ouput.
All uses of os.Exit are removed in favor of returning errors.
Overall this enables better testing and reuse of code. Previously we had to
rely on external unit testing for CLI tests, which are harder to write tests.
Unfortunately kingpin doesn't support natively support aliased flag names, so
you can supply both --start-tls and --starttls without an error, but that's
just "holding it wrong".
I found some servers don't always return a space after the three-digit code
for example,
certigo connect --start-tls ftp ftp.mirrorservice.org:21
error connecting: FTP server responded with status 220-----------------------------------------------------------------------------
, was expecting 220
Instead, we always take the first three digits and parse them as an integer, rather than
relying on the space. Makes the code look a little cleaner too, by returning it as an int.
If otherwise unspecified, default to port 443.
If a starttls protocol is given, use a protocol-specific default.
So now "certigo connect squareup.com" works.
This moves two functions out of main.go.
The only change to the functions was to make them take arguments, instead of using global variables in main.
The mysql and psql imports are moved here too.