func main() {
	var releaseArgs ReleaseSlice
	var stemcellArg string

	showVer := flag.Bool("v", false, "show version information and exit")

	flag.Var(&releaseArgs, "release", "release name/version (multiple)")
	flag.StringVar(&stemcellArg, "stemcell", "", "stemcell name/version (single)")
	flag.Parse()

	if *showVer {
		fmt.Printf("version %s\n", version)
		os.Exit(0)
	}

	if len(releaseArgs) == 0 {
		exitWithUsage("must specify at least one release")
	}

	if stemcellArg == "" {
		exitWithUsage("must specify a stemcell")
	}

	var releases []artifact.Artifact
	for i := range releaseArgs {
		release, err := artifact.New(releaseArgs[i])
		if err != nil {
			exitWithUsage(err.Error())
		}
		releases = append(releases, release)
	}

	stemcell, err := artifact.New(stemcellArg)
	if err != nil {
		exitWithUsage(err.Error())
	}

	r, err := receipt.New(releases, stemcell)
	if err != nil {
		exitWithUsage(err.Error())
	}

	prettyJSON, err := json.MarshalIndent(r, "", "  ")
	if err != nil {
		exitWithUsage(fmt.Sprintf("generating JSON: %s", err))
	}

	fmt.Println(string(prettyJSON))
}
	"github.com/cloudfoundry-incubator/bosh-certification-receipt-generator/receipt"

	. "github.com/onsi/ginkgo"
	. "github.com/onsi/gomega"
)

var _ = Describe("Receipt", func() {
	Describe("New", func() {
		It("creates a new Receipt from valid Artifacts", func() {
			release, err := artifact.New("release/version")
			Expect(err).ToNot(HaveOccurred())

			stemcell, err := artifact.New("stemcell/version")
			Expect(err).ToNot(HaveOccurred())

			subject, err := receipt.New([]artifact.Artifact{release}, stemcell)
			Expect(err).ToNot(HaveOccurred())

			Expect(len(subject.Releases)).To(Equal(1))
			Expect(subject.Releases[0]).To(Equal(release))
			Expect(subject.Stemcell).To(Equal(stemcell))
		})

		It("returns an error when no releases are specified", func() {
			stemcell, err := artifact.New("stemcell/version")
			Expect(err).ToNot(HaveOccurred())

			subject, err := receipt.New([]artifact.Artifact{}, stemcell)
			Expect(subject).To(Equal(receipt.Receipt{}))
			Expect(err).To(MatchError("must include at least one release in receipt"))
		})