Shopify/brigade — pull request #7 by aybabtme (2014-07-10 00:46:24+00:00)
Title: Combine commands in a CLI app.

r: @fbogsany, @camilo,
cc: @Shopify/webscale

Combines the subpackages in `cmd` to create a CLI app.

```bash
$ brigade
NAME:
brigade - Toolkit to list and sync S3 buckets.

USAGE:
brigade [global options] command [command options] [arguments...]

VERSION:
0.0.1 (cli, ed53ae6)

COMMANDS:
list	Lists the keys in an S3 bucket.
sync	Syncs the keys from a source S3 bucket to another.
slice	Slice an S3 key listing into multiple sub-listings.
diff	Generates a differential listing of S3 keys.
help, h	Shows a list of commands or help for one command

GLOBAL OPTIONS:
--version, -v	print the version
--help, -h	show help
```

The PR is 3 parts:

1. `cli.go`: I separate the flags and `cli.Context` handler into funcs so that the flags are close to the context. It makes it easier (IMHO) to retrieve the flag names and values.
2. `main.go`: setups the loggers, pprof HTTP handler and signal catchers.
3. `Makefile`: depends on Godep vendored dependencies. They are not part of this PR to keep the listing readable. Otherwise the `Godeps/_workspace` is (will be) checked into the repo.

### pprof

To help tracing and debugging long running tasks (syncing/listing can take many hours), I setup a `pprof` HTTP server on port 6060. I thought making it optional, but after all I think this should be on all the time so it's there when you need it **or** I could start it when a signal is sent: **suggestions welcome**.

### signals

While trying brigade out, it occured twice that I killed (Ctrl+C) a sync after ~10h of it running. To avoid that, I listen for signals and exits if 2 signals are fired within 5 seconds. This gives a chance to forgive human error.

I'm not sure how that would play when brigade is ran by `runit`: **suggestions welcome**.

### loggers

I'm thinking of using [glog](https://github.com/golang/glog) to replace what's currently there. Meanwhile wrapping log outputs with stdlib `tabwriter` makes for pretty aligned lines.

### Missing: statsd, errbit

I'll revisit those in a future PR to change the way I collect metrics. During long running commands. For now, they print to stdout using the logger.

I'll also add errbit reporting at that point. Suggestions as to how I could go about this are welcome.