forked from attic-labs/noms
-
Notifications
You must be signed in to change notification settings - Fork 0
/
noms_ds.go
49 lines (40 loc) · 1.32 KB
/
noms_ds.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
// Copyright 2016 Attic Labs, Inc. All rights reserved.
// Licensed under the Apache License, version 2.0:
// http://www.apache.org/licenses/LICENSE-2.0
package main
import (
"fmt"
"github.com/attic-labs/kingpin"
"github.com/ndau/noms/cmd/util"
"github.com/ndau/noms/go/config"
"github.com/ndau/noms/go/d"
"github.com/ndau/noms/go/types"
)
func nomsDs(noms *kingpin.Application) (*kingpin.CmdClause, util.KingpinHandler) {
cmd := noms.Command("ds", "Dataset management.")
del := cmd.Flag("delete", "delete a dataset").Short('d').Bool()
name := cmd.Arg("name", "name of the database to list or dataset to delete - see Spelling Objects at https://github.com/ndau/noms/blob/master/doc/spelling.md").String()
return cmd, func(input string) int {
cfg := config.NewResolver()
if *del {
db, set, err := cfg.GetDataset(*name)
d.CheckError(err)
defer db.Close()
oldCommitRef, errBool := set.MaybeHeadRef()
if !errBool {
d.CheckError(fmt.Errorf("Dataset %v not found", set.ID()))
}
_, err = set.Database().Delete(set)
d.CheckError(err)
fmt.Printf("Deleted %v (was #%v)\n", *name, oldCommitRef.TargetHash().String())
} else {
store, err := cfg.GetDatabase(*name)
d.CheckError(err)
defer store.Close()
store.Datasets().IterAll(func(k, v types.Value) {
fmt.Println(k)
})
}
return 0
}
}