in api-generator/main.go [41:93]
func main() {
app := cli.NewApp()
var inputPath, outputPath string
app.Name = "api-generator"
app.Usage = "Converts a protobuf FileDescriptorSet into Type (et al) objects"
app.Flags = []cli.Flag{
cli.StringFlag{
Name: "input, i",
Usage: "the input file containing a FileDescriptorSet",
Destination: &inputPath,
},
cli.StringFlag{
Name: "output, o",
Usage: "the output file pattern where '{name}' will be substituted with the type name",
Destination: &outputPath,
},
}
app.Action = func(c *cli.Context) error {
if len(inputPath) == 0 {
return errors.Errorf("no input file specified")
}
if len(outputPath) == 0 {
return errors.Errorf("no output file specified")
}
in, err := ioutil.ReadFile(inputPath)
if err != nil {
return errors.Wrapf(err, "error reading input file %s", inputPath)
}
fds := &descriptor.FileDescriptorSet{}
if err := proto.Unmarshal(in, fds); err != nil {
return errors.Wrapf(err, "failed to parse file descriptor set")
}
output := new(output)
if err := buildFileSetTypes(fds, output); err != nil {
return errors.Wrap(err, "failed to build API descriptions")
}
if err := emit(outputPath, output); err != nil {
return errors.Wrapf(err, "failed to emit output to %s", outputPath)
}
return nil
}
err := app.Run(os.Args)
if err != nil {
log.Fatalln(err)
}
}