Introduce `noms struct name`
@@ -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():
@@ -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
@@ -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]) {
