Пример #1
0
func addPerson(ds dataset.Dataset) {
	if flag.NArg() != 4 {
		fmt.Fprintln(os.Stderr, "Not enough arguments for command add-person")
		return
	}

	id, err := strconv.ParseUint(flag.Arg(1), 10, 64)
	if err != nil {
		fmt.Fprintf(os.Stderr, "Invalid person-id: %s", flag.Arg(1))
		return
	}

	np := types.NewStruct("Person", types.StructData{
		"id":    types.Number(id),
		"name":  types.String(flag.Arg(2)),
		"title": types.String(flag.Arg(3)),
	})

	_, err = ds.CommitValue(getPersons(ds).Set(types.Number(id), np))
	if err != nil {
		fmt.Fprintf(os.Stderr, "Error committing: %s\n", err)
		return
	}
}
Пример #2
0
func addCommitWithValue(ds dataset.Dataset, v types.Value) (dataset.Dataset, error) {
	return ds.CommitValue(v)
}
Пример #3
0
func addCommit(ds dataset.Dataset, v string) (dataset.Dataset, error) {
	return ds.CommitValue(types.String(v))
}