@@ -26,6 +26,7 @@ Supports range syntax (main..feature) or explicit --from/--to flags.`,
2626 diffCmd .Flags ().String ("from" , "" , "Starting commit (default: HEAD)" )
2727 diffCmd .Flags ().String ("to" , "" , "Ending commit (default: working tree)" )
2828 diffCmd .Flags ().StringP ("ecosystem" , "e" , "" , "Filter by ecosystem" )
29+ diffCmd .Flags ().StringP ("type" , "t" , "" , "Filter by dependency type (runtime, development, etc.)" )
2930 diffCmd .Flags ().StringP ("format" , "f" , "text" , "Output format: text, json" )
3031 parent .AddCommand (diffCmd )
3132}
@@ -40,6 +41,7 @@ type DiffEntry struct {
4041 Name string `json:"name"`
4142 Ecosystem string `json:"ecosystem,omitempty"`
4243 ManifestPath string `json:"manifest_path"`
44+ DependencyType string `json:"dependency_type,omitempty"`
4345 FromRequirement string `json:"from_requirement,omitempty"`
4446 ToRequirement string `json:"to_requirement,omitempty"`
4547}
@@ -48,6 +50,7 @@ func runDiff(cmd *cobra.Command, args []string) error {
4850 fromRef , _ := cmd .Flags ().GetString ("from" )
4951 toRef , _ := cmd .Flags ().GetString ("to" )
5052 ecosystem , _ := cmd .Flags ().GetString ("ecosystem" )
53+ depType , _ := cmd .Flags ().GetString ("type" )
5154 format , _ := cmd .Flags ().GetString ("format" )
5255
5356 // Parse range syntax if provided
@@ -85,9 +88,9 @@ func runDiff(cmd *cobra.Command, args []string) error {
8588 return err
8689 }
8790
88- // Apply ecosystem filter
89- if ecosystem != "" {
90- result = filterDiffResult (result , ecosystem )
91+ // Apply filters
92+ if ecosystem != "" || depType != "" {
93+ result = filterDiffResult (result , ecosystem , depType )
9194 }
9295
9396 if len (result .Added ) == 0 && len (result .Modified ) == 0 && len (result .Removed ) == 0 {
@@ -176,16 +179,18 @@ func computeDiff(fromDeps, toDeps []database.Dependency) *DiffResult {
176179 Name : toDep .Name ,
177180 Ecosystem : toDep .Ecosystem ,
178181 ManifestPath : toDep .ManifestPath ,
182+ DependencyType : toDep .DependencyType ,
179183 FromRequirement : fromDep .Requirement ,
180184 ToRequirement : toDep .Requirement ,
181185 })
182186 }
183187 } else {
184188 result .Added = append (result .Added , DiffEntry {
185- Name : toDep .Name ,
186- Ecosystem : toDep .Ecosystem ,
187- ManifestPath : toDep .ManifestPath ,
188- ToRequirement : toDep .Requirement ,
189+ Name : toDep .Name ,
190+ Ecosystem : toDep .Ecosystem ,
191+ ManifestPath : toDep .ManifestPath ,
192+ DependencyType : toDep .DependencyType ,
193+ ToRequirement : toDep .Requirement ,
189194 })
190195 }
191196 }
@@ -197,6 +202,7 @@ func computeDiff(fromDeps, toDeps []database.Dependency) *DiffResult {
197202 Name : fromDep .Name ,
198203 Ecosystem : fromDep .Ecosystem ,
199204 ManifestPath : fromDep .ManifestPath ,
205+ DependencyType : fromDep .DependencyType ,
200206 FromRequirement : fromDep .Requirement ,
201207 })
202208 }
@@ -219,23 +225,35 @@ func sortDiffEntries(entries []DiffEntry) {
219225 })
220226}
221227
222- func filterDiffResult (result * DiffResult , ecosystem string ) * DiffResult {
228+ func filterDiffResult (result * DiffResult , ecosystem , depType string ) * DiffResult {
223229 filtered := & DiffResult {}
224230
225231 for _ , e := range result .Added {
226- if strings .EqualFold (e .Ecosystem , ecosystem ) {
227- filtered . Added = append ( filtered . Added , e )
232+ if ecosystem != "" && ! strings .EqualFold (e .Ecosystem , ecosystem ) {
233+ continue
228234 }
235+ if depType != "" && ! strings .EqualFold (e .DependencyType , depType ) {
236+ continue
237+ }
238+ filtered .Added = append (filtered .Added , e )
229239 }
230240 for _ , e := range result .Modified {
231- if strings .EqualFold (e .Ecosystem , ecosystem ) {
232- filtered .Modified = append (filtered .Modified , e )
241+ if ecosystem != "" && ! strings .EqualFold (e .Ecosystem , ecosystem ) {
242+ continue
243+ }
244+ if depType != "" && ! strings .EqualFold (e .DependencyType , depType ) {
245+ continue
233246 }
247+ filtered .Modified = append (filtered .Modified , e )
234248 }
235249 for _ , e := range result .Removed {
236- if strings .EqualFold (e .Ecosystem , ecosystem ) {
237- filtered .Removed = append (filtered .Removed , e )
250+ if ecosystem != "" && ! strings .EqualFold (e .Ecosystem , ecosystem ) {
251+ continue
252+ }
253+ if depType != "" && ! strings .EqualFold (e .DependencyType , depType ) {
254+ continue
238255 }
256+ filtered .Removed = append (filtered .Removed , e )
239257 }
240258
241259 return filtered
@@ -255,6 +273,9 @@ func outputDiffText(cmd *cobra.Command, result *DiffResult) error {
255273 if e .ToRequirement != "" {
256274 line += fmt .Sprintf (" %s" , e .ToRequirement )
257275 }
276+ if e .DependencyType != "" && e .DependencyType != "runtime" {
277+ line += fmt .Sprintf (" [%s]" , e .DependencyType )
278+ }
258279 line += fmt .Sprintf (" %s" , Dim ("(" + e .ManifestPath + ")" ))
259280 _ , _ = fmt .Fprintln (cmd .OutOrStdout (), line )
260281 }
@@ -265,6 +286,9 @@ func outputDiffText(cmd *cobra.Command, result *DiffResult) error {
265286 _ , _ = fmt .Fprintln (cmd .OutOrStdout (), Bold ("Modified:" ))
266287 for _ , e := range result .Modified {
267288 line := fmt .Sprintf (" %s %s %s -> %s" , Yellow ("~" ), Yellow (e .Name ), Dim (e .FromRequirement ), e .ToRequirement )
289+ if e .DependencyType != "" && e .DependencyType != "runtime" {
290+ line += fmt .Sprintf (" [%s]" , e .DependencyType )
291+ }
268292 line += fmt .Sprintf (" %s" , Dim ("(" + e .ManifestPath + ")" ))
269293 _ , _ = fmt .Fprintln (cmd .OutOrStdout (), line )
270294 }
@@ -278,6 +302,9 @@ func outputDiffText(cmd *cobra.Command, result *DiffResult) error {
278302 if e .FromRequirement != "" {
279303 line += fmt .Sprintf (" %s" , e .FromRequirement )
280304 }
305+ if e .DependencyType != "" && e .DependencyType != "runtime" {
306+ line += fmt .Sprintf (" [%s]" , e .DependencyType )
307+ }
281308 line += fmt .Sprintf (" %s" , Dim ("(" + e .ManifestPath + ")" ))
282309 _ , _ = fmt .Fprintln (cmd .OutOrStdout (), line )
283310 }
0 commit comments