1212from colorama import Fore , Style
1313
1414from vcspull ._internal .config_reader import DuplicateAwareConfigReader
15+ from vcspull ._internal .config_style import apply_config_style
1516from vcspull ._internal .private_path import PrivatePath
1617from vcspull .config import (
1718 find_config_files ,
2021 normalize_workspace_roots ,
2122 save_config_yaml ,
2223)
24+ from vcspull .types import ConfigStyle
2325
2426log = logging .getLogger (__name__ )
2527
@@ -50,6 +52,13 @@ def create_fmt_subparser(parser: argparse.ArgumentParser) -> None:
5052 action = "store_false" ,
5153 help = "Do not merge duplicate workspace roots when formatting" ,
5254 )
55+ parser .add_argument (
56+ "--style" ,
57+ dest = "style" ,
58+ choices = ["concise" , "standard" , "verbose" ],
59+ default = None ,
60+ help = "Convert repo entries to the specified style (concise, standard, verbose)" ,
61+ )
5362 parser .set_defaults (merge_roots = True )
5463
5564
@@ -81,13 +90,18 @@ def normalize_repo_config(repo_data: t.Any) -> dict[str, t.Any]:
8190 return t .cast ("dict[str, t.Any]" , repo_data )
8291
8392
84- def format_config (config_data : dict [str , t .Any ]) -> tuple [dict [str , t .Any ], int ]:
93+ def format_config (
94+ config_data : dict [str , t .Any ],
95+ style : ConfigStyle | None = None ,
96+ ) -> tuple [dict [str , t .Any ], int ]:
8597 """Format vcspull configuration for consistency.
8698
8799 Parameters
88100 ----------
89101 config_data : dict
90102 Raw configuration data
103+ style : ConfigStyle | None
104+ When set, convert all repo entries to this style after sorting.
91105
92106 Returns
93107 -------
@@ -132,6 +146,20 @@ def format_config(config_data: dict[str, t.Any]) -> tuple[dict[str, t.Any], int]
132146 if list (config_data .keys ()) != sorted_dirs :
133147 changes += 1
134148
149+ # Apply style conversion if requested
150+ if style is not None :
151+ formatted , style_changes , style_warnings = apply_config_style (
152+ formatted , style = style
153+ )
154+ changes += style_changes
155+ for warning in style_warnings :
156+ log .warning (
157+ "%s•%s %s" ,
158+ Fore .YELLOW ,
159+ Style .RESET_ALL ,
160+ warning ,
161+ )
162+
135163 return formatted , changes
136164
137165
@@ -140,6 +168,7 @@ def format_single_config(
140168 write : bool ,
141169 * ,
142170 merge_roots : bool ,
171+ style : ConfigStyle | None = None ,
143172) -> bool :
144173 """Format a single vcspull configuration file.
145174
@@ -151,6 +180,8 @@ def format_single_config(
151180 Whether to write changes back to file
152181 merge_roots : bool
153182 Merge duplicate workspace roots when True (default behavior)
183+ style : ConfigStyle | None
184+ When set, convert all repo entries to this style.
154185
155186 Returns
156187 -------
@@ -250,7 +281,7 @@ def format_single_config(
250281 for message in duplicate_merge_conflicts :
251282 log .warning (message )
252283
253- formatted_config , change_count = format_config (normalized_config )
284+ formatted_config , change_count = format_config (normalized_config , style = style )
254285 change_count += normalization_changes + duplicate_merge_changes
255286
256287 if change_count == 0 :
@@ -392,6 +423,7 @@ def format_config_file(
392423 format_all : bool = False ,
393424 * ,
394425 merge_roots : bool = True ,
426+ style : ConfigStyle | None = None ,
395427) -> None :
396428 """Format vcspull configuration file(s).
397429
@@ -405,6 +437,8 @@ def format_config_file(
405437 If True, format all discovered config files
406438 merge_roots : bool
407439 Merge duplicate workspace roots when True (default)
440+ style : ConfigStyle | None
441+ When set, convert all repo entries to this style.
408442 """
409443 if format_all :
410444 # Format all discovered config files
@@ -457,6 +491,7 @@ def format_config_file(
457491 config_file ,
458492 write ,
459493 merge_roots = merge_roots ,
494+ style = style ,
460495 ):
461496 success_count += 1
462497
@@ -508,4 +543,5 @@ def format_config_file(
508543 config_file_path ,
509544 write ,
510545 merge_roots = merge_roots ,
546+ style = style ,
511547 )
0 commit comments