Skip to content
This repository has been archived by the owner on Aug 28, 2021. It is now read-only.

Commit

Permalink
Introduce noms struct name
Browse files Browse the repository at this point in the history
  • Loading branch information
aboodman committed Mar 3, 2018
1 parent 469ee08 commit d5a659a
Showing 1 changed file with 26 additions and 0 deletions.
26 changes: 26 additions & 0 deletions cmd/noms/noms_struct.go
Expand Up @@ -32,6 +32,10 @@ func nomsStruct(noms *kingpin.Application) (*kingpin.CmdClause, util.KingpinHand
delSpec := struktDel.Arg("spec", "value spec for the struct to edit").Required().String()
delFields := struktDel.Arg("fields", "fields to be removed").Strings()

struktName := strukt.Command("name", "updates the name of a struct")
nameSpec := struktName.Arg("spec", "value spec for the struct to edit").Required().String()
nameName := struktName.Arg("name", "new name for the struct").String()

return strukt, func(input string) int {
switch input {
case struktNew.FullCommand():
Expand All @@ -40,6 +44,8 @@ func nomsStruct(noms *kingpin.Application) (*kingpin.CmdClause, util.KingpinHand
return nomsStructSet(*setSpec, *setFields)
case struktDel.FullCommand():
return nomsStructDel(*delSpec, *delFields)
case struktName.FullCommand():
return nomsStructName(*nameSpec, *nameName)
}
d.Panic("notreached")
return 1
Expand Down Expand Up @@ -107,6 +113,26 @@ func nomsStructDel(specStr string, args []string) int {
}
}

func nomsStructName(specStr string, name string) int {
sp, err := spec.ForPath(specStr)
d.PanicIfError(err)
db := sp.GetDatabase()
val := sp.GetValue()
if st, ok := val.(types.Struct); ok {
sd := types.StructData{}
st.IterFields(func(name string, val types.Value) {
sd[name] = val
})
r := db.WriteValue(types.NewStruct(name, sd))
db.Flush()
fmt.Println(r.TargetHash().String())
return 0
} else {
d.CheckError(fmt.Errorf("Path does not resolve to a struct: %s", specStr))
return 1
}
}

func applyStructEdits(db datas.Database, st types.Struct, args []string) {
for i := 0; i < len(args); i += 2 {
if !types.IsValidStructFieldName(args[i]) {
Expand Down

0 comments on commit d5a659a

Please sign in to comment.