code: func (t *Tool) Run(c context.Context, f Generator) error {
  	// Validate arguments.
  	if len(t.FileNames) == 0 {
  		return fmt.Errorf("files not specified")
  	}
  	if len(t.Types) == 0 {
  		return fmt.Errorf("types not specified")
  	}
  
  	// Determine output file name.
  	outputName := t.Output
  	if outputName == "" {
  		if t.Dir == "" {
  			return fmt.Errorf("neither output not dir are specified")
  		}
  		baseName := fmt.Sprintf("%s_%s.go", t.Types[0], t.OutputFilenameSuffix)
  		outputName = filepath.Join(t.Dir, strings.ToLower(baseName))
  	}
  
  	// Parse Go files and resolve specified types.
  	p := &parser{
  		fileSet: token.NewFileSet(),
  		types:   t.Types,
  	}
  	if err := p.parsePackage(t.FileNames); err != nil {
  		return fmt.Errorf("could not parse .go files: %s", err)
  	}
  	if err := p.resolveServices(c); err != nil {
  		return err
  	}
  
  	// Run the generator.
  	var buf bytes.Buffer
  	genArgs := &GeneratorArgs{
  		PackageName:  p.files[0].Name.Name,
  		Services:     p.services,
  		ExtraImports: importSorted(p.extraImports),
  		Out:          &buf,
  	}
  	if err := f(c, genArgs); err != nil {
  		return err
  	}
  
  	// Format the output.
  	src, err := format.Source(buf.Bytes())
  	if err != nil {
  		println(buf.String())
  		return fmt.Errorf("gofmt: %s", err)
  	}
  
  	// Write to file.
  	return ioutil.WriteFile(outputName, src, 0644)
  }
docs: // Run parses Go files and generates a new file using f.