Use getopt to enable iteration of headers

Change-Id: I1b2c4e51c02e969997e6b22322128ca1a819c08d
Reviewed-on: http://review.couchbase.org/43844
Tested-by: buildbot <build@couchbase.com>
Reviewed-by: Dave Rigby <daver@couchbase.com>