aboutsummaryrefslogtreecommitdiffstats
path: root/bommom.go
diff options
context:
space:
mode:
authorbnewbold <bnewbold@robocracy.org>2012-04-17 20:12:19 -0400
committerbnewbold <bnewbold@robocracy.org>2012-04-17 20:12:19 -0400
commit03f6d8e51152b1862b2d999b79b90a088b06037f (patch)
tree43eea3f6f47558682985daf2ca014e3231653cb7 /bommom.go
parent78b207a40436d0c15a2b806171914d802cd20661 (diff)
downloadbommom-03f6d8e51152b1862b2d999b79b90a088b06037f.zip
bommom-03f6d8e51152b1862b2d999b79b90a088b06037f.tar.gz
listing
Diffstat (limited to 'bommom.go')
-rw-r--r--bommom.go67
1 files changed, 64 insertions, 3 deletions
diff --git a/bommom.go b/bommom.go
index 3b7c993..4b6e39d 100644
--- a/bommom.go
+++ b/bommom.go
@@ -41,13 +41,73 @@ func main() {
switch flag.Arg(0) {
default:
log.Fatal("Error: unknown command: ", flag.Arg(0))
- case "load", "dump", "serve":
+ case "load", "serve":
log.Fatal("Error: Unimplemented, sorry")
case "init":
log.Println("Initializing...")
+ initCmd()
+ case "dump":
+ log.Println("Dumping...")
+ dumpCmd()
+ case "list":
+ listCmd()
}
}
+func initCmd() {
+ _, err := NewJSONFileBomStore(*fileStorePath)
+ if err != nil {
+ log.Fatal(err)
+ }
+}
+
+func dumpCmd() {
+ b := makeTestBom()
+ b.Version = "v001"
+ bs := &BomStub{Name: "widget",
+ Owner: "common",
+ Description: "fancy stuff",
+ HeadVersion: b.Version,
+ IsPublicView: true,
+ IsPublicEdit: true}
+ jfbs, err := OpenJSONFileBomStore(*fileStorePath)
+ if err != nil {
+ log.Fatal(err)
+ }
+ jfbs.Persist(bs, b, "v001")
+}
+
+func listCmd() {
+ jfbs, err := OpenJSONFileBomStore(*fileStorePath)
+ if err != nil {
+ log.Fatal(err)
+ }
+ var bomStubs []BomStub
+ if flag.NArg() > 2 {
+ log.Fatal("Error: too many arguments...")
+ }
+ if flag.NArg() == 2 {
+ name := flag.Arg(1)
+ if !isShortName(name) {
+ log.Fatal("Error: not a possible username: " + name)
+ }
+ bomStubs, err = jfbs.ListBoms(ShortName(name))
+ if err != nil {
+ log.Fatal(err)
+ }
+ } else {
+ // list all boms from all names
+ // TODO: ERROR
+ bomStubs, err = jfbs.ListBoms("")
+ if err != nil {
+ log.Fatal(err)
+ }
+ }
+ for _, bs := range bomStubs {
+ fmt.Println(bs.Owner + "/" + bs.Name)
+ }
+}
+
func printUsage() {
fmt.Println("bommom is a tool for managing and publishing electronics BOMs")
fmt.Println("")
@@ -57,8 +117,9 @@ func printUsage() {
fmt.Println("Commands:")
fmt.Println("")
fmt.Println("\tinit \t\t initialize BOM and authentication datastores")
- fmt.Println("\tload [file]\t import a BOM")
- fmt.Println("\tdump [name]\t dump a BOM to stdout")
+ fmt.Println("\tlist [user]\t\t list BOMs, optionally filtered by user")
+ fmt.Println("\tload <file>\t import a BOM")
+ fmt.Println("\tdump <user> <name>\t dump a BOM to stdout")
fmt.Println("\tserve\t\t serve up web interface over HTTP")
fmt.Println("")
fmt.Println("Extra command line options:")