github.com/ndau/noms@v1.0.5/cmd/noms/noms_blob.go (about)

     1  // Copyright 2016 Attic Labs, Inc. All rights reserved.
     2  // Licensed under the Apache License, version 2.0:
     3  // http://www.apache.org/licenses/LICENSE-2.0
     4  
     5  package main
     6  
     7  import (
     8  	"runtime"
     9  	"strconv"
    10  
    11  	"github.com/attic-labs/kingpin"
    12  
    13  	"github.com/ndau/noms/cmd/util"
    14  	"github.com/ndau/noms/go/d"
    15  )
    16  
    17  func nomsBlob(noms *kingpin.Application) (*kingpin.CmdClause, util.KingpinHandler) {
    18  	blob := noms.Command("blob", "Interact with blobs.")
    19  
    20  	blobPut := blob.Command("put", "imports a blob to a dataset")
    21  	concurrency := blobPut.Flag("concurrency", "number of concurrent HTTP calls to retrieve remote resources").Default(strconv.Itoa(runtime.NumCPU())).Int()
    22  	putFile := blobPut.Arg("file", "a file to import").Required().String()
    23  	putDB := blobPut.Arg("dbSpec", "the database to import into").String()
    24  
    25  	blobGet := blob.Command("export", "exports a blob from a dataset")
    26  	getDs := blobGet.Arg("dataset", "the dataset to export").Required().String()
    27  	getPath := blobGet.Arg("file", "an optional file to save the blob to").String()
    28  
    29  	return blob, func(input string) int {
    30  		switch input {
    31  		case blobPut.FullCommand():
    32  			return nomsBlobPut(*putFile, *putDB, *concurrency)
    33  		case blobGet.FullCommand():
    34  			return nomsBlobGet(*getDs, *getPath)
    35  		}
    36  		d.Panic("notreached")
    37  		return 1
    38  	}
    39  }