@@ -21,8 +21,8 @@ type Protolock struct {
2121}
2222
2323type Definition struct {
24- Filepath Protopath `json:"protopath,omitempty"`
25- Def Entry `json:"def,omitempty"`
24+ Filepath * Protopath `json:"protopath,omitempty"`
25+ Def Entry `json:"def,omitempty"`
2626}
2727
2828type Entry struct {
@@ -49,14 +49,14 @@ type Option struct {
4949}
5050
5151type Message struct {
52- Name string `json:"name,omitempty"`
53- Fields []Field `json:"fields,omitempty"`
54- Maps []Map `json:"maps,omitempty"`
55- ReservedIDs []int `json:"reserved_ids,omitempty"`
56- ReservedNames []string `json:"reserved_names,omitempty"`
57- Filepath Protopath `json:"filepath,omitempty"`
58- Messages []Message `json:"messages,omitempty"`
59- Options []Option `json:"options,omitempty"`
52+ Name string `json:"name,omitempty"`
53+ Fields []Field `json:"fields,omitempty"`
54+ Maps []Map `json:"maps,omitempty"`
55+ ReservedIDs []int `json:"reserved_ids,omitempty"`
56+ ReservedNames []string `json:"reserved_names,omitempty"`
57+ Filepath * Protopath `json:"filepath,omitempty"`
58+ Messages []Message `json:"messages,omitempty"`
59+ Options []Option `json:"options,omitempty"`
6060}
6161
6262type EnumField struct {
@@ -90,9 +90,9 @@ type Field struct {
9090}
9191
9292type Service struct {
93- Name string `json:"name,omitempty"`
94- RPCs []RPC `json:"rpcs,omitempty"`
95- Filepath Protopath `json:"filepath,omitempty"`
93+ Name string `json:"name,omitempty"`
94+ RPCs []RPC `json:"rpcs,omitempty"`
95+ Filepath * Protopath `json:"filepath,omitempty"`
9696}
9797
9898type RPC struct {
@@ -111,13 +111,13 @@ type Report struct {
111111}
112112
113113type Warning struct {
114- Filepath Protopath `json:"filepath,omitempty"`
115- Message string `json:"message,omitempty"`
116- RuleName string `json:"rulename,omitempty"`
114+ Filepath * Protopath `json:"filepath,omitempty"`
115+ Message string `json:"message,omitempty"`
116+ RuleName string `json:"rulename,omitempty"`
117117}
118118
119119type ProtoFile struct {
120- ProtoPath Protopath
120+ ProtoPath * Protopath
121121 Entry Entry
122122}
123123
@@ -512,10 +512,10 @@ func Compare(current, update Protolock) (*Report, error) {
512512}
513513
514514// getProtoFiles finds recursively all .proto files to be processed.
515- func getProtoFiles (root string , ignores string ) ([]string , error ) {
515+ func getProtoFiles (root string , ignores string , includes [] string ) ([]string , error ) {
516516 protoFiles := []string {}
517517
518- err := filepath . Walk ( root , func (path string , info os.FileInfo , err error ) error {
518+ protoWalker := func (path string , info os.FileInfo , err error ) error {
519519 if err != nil {
520520 return err
521521 }
@@ -547,11 +547,22 @@ func getProtoFiles(root string, ignores string) ([]string, error) {
547547 protoFiles = append (protoFiles , path )
548548
549549 return nil
550- })
550+ }
551+
552+ err := filepath .Walk (root , protoWalker )
551553 if err != nil {
552554 return nil , err
553555 }
554556
557+ if len (includes ) > 0 {
558+ for _ , i := range includes {
559+ err := filepath .Walk (i , protoWalker )
560+ if err != nil {
561+ return nil , err
562+ }
563+ }
564+ }
565+
555566 return protoFiles , nil
556567}
557568
@@ -566,7 +577,7 @@ func getUpdatedLock(cfg Config) (*Protolock, error) {
566577 return nil , err
567578 }
568579
569- protoFiles , err := getProtoFiles (root , cfg .Ignore )
580+ protoFiles , err := getProtoFiles (root , cfg .Ignore , cfg . Includes )
570581 if err != nil {
571582 return nil , err
572583 }
@@ -593,9 +604,27 @@ func getUpdatedLock(cfg Config) (*Protolock, error) {
593604 }
594605
595606 localPath := strings .TrimPrefix (path , root )
607+ isProtoRootFile := localPath != path
596608 localPath = strings .TrimPrefix (localPath , string (filepath .Separator ))
609+
610+ var pathType string
611+ if isProtoRootFile {
612+ pathType = "protodir"
613+ } else {
614+ includesPos := 0
615+ for pos , include := range cfg .Includes {
616+ if strings .HasPrefix (localPath , include ) {
617+ includesPos = pos
618+ break
619+ }
620+ }
621+ pathType = fmt .Sprintf ("includes%d" , includesPos )
622+ localPath = strings .TrimPrefix (path , cfg .Includes [includesPos ])
623+ localPath = strings .TrimPrefix (localPath , string (filepath .Separator ))
624+ }
625+
597626 protoFile := ProtoFile {
598- ProtoPath : ProtoPath ( Protopath ( localPath )) ,
627+ ProtoPath : & Protopath { localPath , pathType } ,
599628 Entry : entry ,
600629 }
601630 files = append (files , protoFile )
0 commit comments