Skip to content

Commit 440a8bd

Browse files
committed
apidocs: Add trimprefix option
1 parent 99352d3 commit 440a8bd

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

main.go

+5
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ func main() {
2121
var flags flag.FlagSet
2222
format := flags.String("format", "markdown", "Format to use")
2323
templates := flags.String("templates", "", "Custom templates directory to use")
24+
trimPrefix := flags.String("trimprefix", "", "If supplied, this prefix will be removed from generated file paths.")
2425

2526
opts := &protogen.Options{
2627
ParamFunc: flags.Set,
@@ -29,6 +30,7 @@ func main() {
2930
genOpts := GenOpts{
3031
Format: *format,
3132
TemplateDir: *templates,
33+
TrimPrefix: *trimPrefix,
3234
}
3335
for _, f := range gen.Files {
3436
if !f.Generate {
@@ -46,6 +48,7 @@ func main() {
4648
type GenOpts struct {
4749
Format string
4850
TemplateDir string
51+
TrimPrefix string
4952
}
5053

5154
var formatFileSuffixes = map[string]string{
@@ -60,6 +63,7 @@ func (o *GenOpts) generateFile(gen *protogen.Plugin, file *protogen.File) error
6063
suffix = o.Format
6164
}
6265
filename := file.GeneratedFilenamePrefix + "." + suffix
66+
filename = strings.TrimPrefix(filename, o.TrimPrefix)
6367
g := gen.NewGeneratedFile(filename, file.GoImportPath)
6468
if err := o.renderTemplate(file, g); err != nil {
6569
return fmt.Errorf("issue generating %v: %w", filename, err)
@@ -200,6 +204,7 @@ func (o *GenOpts) getTemplateFS() (fs.FS, error) {
200204
tFS := os.DirFS(o.TemplateDir)
201205
return fs.Sub(tFS, o.TemplateDir)
202206
}
207+
203208
func (o *GenOpts) renderTemplate(file *protogen.File, g *protogen.GeneratedFile) error {
204209
tFS, err := o.getTemplateFS()
205210
if err != nil {

0 commit comments

Comments
 (0)