From b6a2d46c5bbdca7ca5d3e50eece732b5b839f2c5 Mon Sep 17 00:00:00 2001 From: bnewbold Date: Wed, 18 Apr 2012 23:12:11 -0400 Subject: bom load versioning --- bommom.go | 13 ++++++++++++- core.go | 4 +--- formats.go | 17 ++++++++++++----- 3 files changed, 25 insertions(+), 9 deletions(-) diff --git a/bommom.go b/bommom.go index 42e0a1c..83f2610 100644 --- a/bommom.go +++ b/bommom.go @@ -247,7 +247,7 @@ func loadCmd() { } func convertCmd() { - if flag.NArg() != 3 { + if flag.NArg() != 2 && flag.NArg() != 3 { log.Fatal("Error: wrong number of arguments (expected input and output files)") } @@ -258,10 +258,21 @@ func convertCmd() { outFname := flag.Arg(2) bs, b := loadIn(inFname) + + if b == nil { + log.Fatal("null bom") + } if inFormat == "csv" && bs == nil { // TODO: from inname? if ShortName? bs = &BomStub{Name: "untitled", Owner: anonUser.name} } + + if err := bs.Validate(); err != nil { + log.Fatal("loaded bomstub not valid: " + err.Error()) + } + if err := b.Validate(); err != nil { + log.Fatal("loaded bom not valid: " + err.Error()) + } dumpOut(outFname, bs, b) } diff --git a/core.go b/core.go index 1d6debd..6a79896 100644 --- a/core.go +++ b/core.go @@ -81,9 +81,7 @@ func (b *Bom) Validate() error { if !isShortName(b.Version) { return Error("version not a ShortName: \"" + b.Version + "\"") } - // TODO: nil? what is zero of Time? - nullTime := time.Time{} - if b.Created == nullTime { + if &b.Created == nil { return Error("created timestamp not defined") } return nil diff --git a/formats.go b/formats.go index 2412a13..5d93f80 100644 --- a/formats.go +++ b/formats.go @@ -96,19 +96,26 @@ func DumpBomAsJSON(bs *BomStub, b *Bom, out io.Writer) { func LoadBomFromJSON(input io.Reader) (*BomStub, *Bom, error) { - bs := BomStub{} - b := Bom{} + bs := &BomStub{} + b := &Bom{} obj := map[string]interface{}{ - "bom_meta": bs, - "bom": b, + "bom_meta": &bs, + "bom": &b, } + fmt.Println(obj) + enc := json.NewDecoder(input) if err := enc.Decode(&obj); err != nil { log.Fatal(err) } - return &bs, &b, nil + if &bs == nil || &b == nil { + log.Fatal("didn't load successfully") + } + fmt.Println(bs) + fmt.Println(b) + return bs, b, nil } // --------------------- XML ----------------------- -- cgit v1.2.3