code: func writeTypes(args *internal.ArgType) error {
  	var err error
  
  	out := internal.TBufSlice(args.Generated)
  
  	// sort segments
  	sort.Sort(out)
  
  	// loop, writing in order
  	for _, t := range out {
  		var f *os.File
  
  		// skip when in append and type is XO
  		if args.Append && t.TemplateType == internal.XOTemplate {
  			continue
  		}
  
  		// check if generated template is only whitespace/empty
  		bufStr := strings.TrimSpace(t.Buf.String())
  		if len(bufStr) == 0 {
  			continue
  		}
  
  		// get file and filename
  		f, err = getFile(args, &t)
  		if err != nil {
  			return err
  		}
  
  		// should only be nil when type == xo
  		if f == nil {
  			continue
  		}
  
  		// write segment
  		if !args.Append || (t.TemplateType != internal.TypeTemplate && t.TemplateType != internal.QueryTypeTemplate) {
  			_, err = t.Buf.WriteTo(f)
  			if err != nil {
  				return err
  			}
  		}
  	}
  
  	// build goimports parameters, closing files
  	params := []string{"-w"}
  	for k, f := range files {
  		params = append(params, k)
  
  		// close
  		err = f.Close()
  		if err != nil {
  			return err
  		}
  	}
  
  	// process written files with goimports
  	output, err := exec.Command("goimports", params...).CombinedOutput()
  	if err != nil {
  		return errors.New(string(output))
  	}
  
  	return nil
  }
docs: // writeTypes writes the generated definitions.