11from pathlib import Path
2+ from typing import List , Set
23
34from cleo .helpers import option
45from poetry .console .commands .command import Command
@@ -13,33 +14,66 @@ class DiffCommand(Command):
1314 option (
1415 long_name = "short" ,
1516 short_name = "s" ,
16- description = "Print only changed projects" ,
17+ description = "Print short view" ,
18+ flag = True ,
19+ ),
20+ option (
21+ long_name = "bricks" ,
22+ description = "Print changed bricks" ,
1723 flag = True ,
1824 ),
1925 ]
2026
27+ def has_partial_options (self ) -> bool :
28+ return any (self .option (k ) for k in {"bricks" })
29+
30+ def print_partial_views (
31+ self ,
32+ affected_projects : Set [str ],
33+ bases : List [str ],
34+ components : List [str ],
35+ ) -> None :
36+ short = self .option ("short" )
37+
38+ if short and not self .has_partial_options ():
39+ diff .report .print_projects_affected_by_changes (affected_projects , short )
40+
41+ return
42+
43+ if self .option ("bricks" ):
44+ diff .report .print_detected_changes_in_bricks (bases , components , short )
45+
46+ def print_views (self , root : Path , tag : str ) -> None :
47+ ns = workspace .parser .get_namespace_from_config (root )
48+ files = diff .collect .get_files (tag )
49+ bases = diff .collect .get_changed_bases (files , ns )
50+ components = diff .collect .get_changed_components (files , ns )
51+ projects = diff .collect .get_changed_projects (files )
52+ all_projects_data = info .get_bricks_in_projects (root , components , bases , ns )
53+ projects_data = [p for p in all_projects_data if info .is_project (p )]
54+
55+ affected_projects = diff .collect .get_projects_affected_by_changes (
56+ projects_data , projects , bases , components
57+ )
58+
59+ short = self .option ("short" )
60+
61+ if not short and not self .has_partial_options ():
62+ diff .report .print_diff_summary (tag , bases , components )
63+ diff .report .print_detected_changes_in_projects (projects , short )
64+ diff .report .print_diff_details (projects_data , bases , components )
65+
66+ return
67+
68+ self .print_partial_views (affected_projects , bases , components )
69+
2170 def handle (self ) -> int :
2271 root = repo .get_workspace_root (Path .cwd ())
2372 tag = diff .collect .get_latest_tag (root )
2473
2574 if not tag :
2675 self .line ("No tags found in repository." )
2776 else :
28- ns = workspace .parser .get_namespace_from_config (root )
29- files = diff .collect .get_files (tag )
30- bases = diff .collect .get_changed_bases (files , ns )
31- components = diff .collect .get_changed_components (files , ns )
32- projects = diff .collect .get_changed_projects (files )
33- all_projects_data = info .get_bricks_in_projects (root , components , bases , ns )
34- projects_data = [p for p in all_projects_data if info .is_project (p )]
35-
36- short = self .option ("short" )
37-
38- if short :
39- diff .report .print_short_diff (projects_data , projects , bases , components )
40- else :
41- diff .report .print_diff_summary (tag , bases , components )
42- diff .report .print_detected_changes_in_projects (projects )
43- diff .report .print_diff_details (projects_data , bases , components )
77+ self .print_views (root , tag )
4478
4579 return 0
0 commit comments