@@ -6,14 +6,30 @@ namespace SonarRulesetTool.Commands;
66
77internal static class NormalizeCommand
88{
9- public static Command Register ( )
9+ public static Command Create ( )
1010 {
11- var inputFileArgument = new Argument < FileInfo > ( "inputFile" , CommandArgumentParser . ParseFileInfo , false ,
12- "Path to the .xml file that contains the SonarCloud profile" ) ;
11+ var inputFileArgument = new Argument < FileInfo > ( "inputFile" )
12+ {
13+ Description = "Path to the .xml file that contains the SonarCloud profile" ,
14+ CustomParser = CommandArgumentParser . ParseFileInfo
15+ } ;
1316
14- var outputFileNameOption = new Option < string ? > ( "--outputFile" , "Path to the normalized output .xml file" ) ;
15- var sortByKeyOption = new Option < bool > ( "--sortByKey" , ( ) => true , "Sort rules alphabetically by key" ) ;
16- var cleanRuleOption = new Option < bool > ( "--cleanRule" , ( ) => true , "Only preserve 'key' and 'repositoryKey' per rule" ) ;
17+ var outputFileNameOption = new Option < string ? > ( "--outputFile" )
18+ {
19+ Description = "Path to the normalized output .xml file (by default, adds -normalized to the file name)"
20+ } ;
21+
22+ var sortByKeyOption = new Option < bool > ( "--sortByKey" )
23+ {
24+ Description = "Sort rules alphabetically by key (default: true)" ,
25+ DefaultValueFactory = _ => true
26+ } ;
27+
28+ var cleanRuleOption = new Option < bool > ( "--cleanRule" )
29+ {
30+ Description = "Only preserve 'key' and 'repositoryKey' per rule (default: true)" ,
31+ DefaultValueFactory = _ => true
32+ } ;
1733
1834 var command = new Command ( "normalize" , "Normalizes an exported SonarCloud .xml file for easy diffing" )
1935 {
@@ -23,15 +39,25 @@ public static Command Register()
2339 cleanRuleOption
2440 } ;
2541
26- command . SetHandler ( HandleCommand , inputFileArgument , outputFileNameOption , sortByKeyOption , cleanRuleOption ) ;
42+ command . SetAction ( parseResult =>
43+ {
44+ FileInfo inputFileInfo = parseResult . GetRequiredValue ( inputFileArgument ) ;
45+ string ? outputFileName = parseResult . GetValue ( outputFileNameOption ) ;
46+ bool sortByKey = parseResult . GetValue ( sortByKeyOption ) ;
47+ bool cleanRule = parseResult . GetValue ( cleanRuleOption ) ;
48+
49+ HandleCommand ( inputFileInfo , outputFileName , sortByKey , cleanRule ) ;
50+ } ) ;
2751
2852 return command ;
2953 }
3054
3155 private static void HandleCommand ( FileInfo inputFileInfo , string ? outputFileName , bool sortByKey , bool cleanRule )
3256 {
3357 string parentDirectory = Path . GetDirectoryName ( inputFileInfo . FullName ) ! ;
34- string outputPath = Path . Combine ( parentDirectory , outputFileName ?? Path . GetFileNameWithoutExtension ( inputFileInfo . Name ) + "-normalized.xml" ) ;
58+
59+ string outputPath = Path . Combine ( parentDirectory ,
60+ outputFileName ?? $ "{ Path . GetFileNameWithoutExtension ( inputFileInfo . Name ) } -normalized{ Path . GetExtension ( inputFileInfo . Name ) } ") ;
3561
3662 NormalizeFile ( inputFileInfo , outputPath , sortByKey , cleanRule ) ;
3763 }
0 commit comments