alanchavez88/gopistrano — pull request #1 by hopkinsth (2014-12-16 04:12:53+00:00)
Title: Feature/refactor

Hey there, I'm just opening this PR to keep track of some changes I think are worth making. Building a capistrano clone is a neat learning project! I don't expect you to merge this PR by any means—just looking to discuss how this all works a little bit, I guess.

In no particular order, here's a summary of what I've changed (so far)...

**added an init() function**
Since this will run automatically, this is a good place to put your several declarations.

**split main() into two different functions**
Using a switch statement makes this much easier to read, and avoiding the use of panic() everywhere makes the program output more readable. You don't need a stack trace for every one of these errors... though it does help sometimes in initial development. I added `deploySetup` and `deploy` functions, both of which return an `error` if any.

**remove use of `scp -t`**
Using the `-t` flag on scp isn't necessary here, and it's meant to be an internal option anyway. SSH runs commands in a real shell on the remote host, so you can use `echo` (or whatever else) to do what you need here. You could do some fancier things with a stdin pipe to a process running `cat`, but this is fine for now... but more about other options for improving that later.

#### other interesting possibilities
You could accomplish all of this in a shell script if you want, but this *is* an interesting learning project for go.
That being the case, why not upload a small go binary that does the file copying magic for you? Using a shell script is far, far more practical, yes. Running all those different programs with Go's `os/exec` – git, ls, tail, etc. – is much more cumbersome, but it would be a neat exercise. And it would be neat to deal with the challenge of uploading a go binary with a go binary :)

Other interesting features – maybe! – would be stuff like...
- supporting github, bitbucket repo downloads: just download a zip, tar file of the repo and decompress it, no git required – could be interesting for some stuff
- multi-target deploys: deploy two things at once or in sequence as needed – this gets complicated, but...

Anyway, mostly just some random thoughts.