@@ -21,6 +21,7 @@ func main() {
21
21
var flags flag.FlagSet
22
22
format := flags .String ("format" , "markdown" , "Format to use" )
23
23
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." )
24
25
25
26
opts := & protogen.Options {
26
27
ParamFunc : flags .Set ,
@@ -29,6 +30,7 @@ func main() {
29
30
genOpts := GenOpts {
30
31
Format : * format ,
31
32
TemplateDir : * templates ,
33
+ TrimPrefix : * trimPrefix ,
32
34
}
33
35
for _ , f := range gen .Files {
34
36
if ! f .Generate {
@@ -46,6 +48,7 @@ func main() {
46
48
type GenOpts struct {
47
49
Format string
48
50
TemplateDir string
51
+ TrimPrefix string
49
52
}
50
53
51
54
var formatFileSuffixes = map [string ]string {
@@ -60,6 +63,7 @@ func (o *GenOpts) generateFile(gen *protogen.Plugin, file *protogen.File) error
60
63
suffix = o .Format
61
64
}
62
65
filename := file .GeneratedFilenamePrefix + "." + suffix
66
+ filename = strings .TrimPrefix (filename , o .TrimPrefix )
63
67
g := gen .NewGeneratedFile (filename , file .GoImportPath )
64
68
if err := o .renderTemplate (file , g ); err != nil {
65
69
return fmt .Errorf ("issue generating %v: %w" , filename , err )
@@ -200,6 +204,7 @@ func (o *GenOpts) getTemplateFS() (fs.FS, error) {
200
204
tFS := os .DirFS (o .TemplateDir )
201
205
return fs .Sub (tFS , o .TemplateDir )
202
206
}
207
+
203
208
func (o * GenOpts ) renderTemplate (file * protogen.File , g * protogen.GeneratedFile ) error {
204
209
tFS , err := o .getTemplateFS ()
205
210
if err != nil {
0 commit comments