11using System ;
22using System . CommandLine ;
3- using System . Linq ;
43using Microsoft . Extensions . DependencyInjection ;
54using PowerUtils . BenchmarkDotnet . Reporter . Commands ;
5+ using PowerUtils . BenchmarkDotnet . Reporter . Options ;
66
77namespace PowerUtils . BenchmarkDotnet . Reporter ;
88
99public sealed class ToolCommands : RootCommand
1010{
1111 public ToolCommands ( IServiceProvider provider )
1212 {
13- var baseline = _createBaselineOption ( ) ;
14- var target = _createTargetOption ( ) ;
13+ var baseline = new BaselineOption ( ) ;
14+ var target = new TargetOption ( ) ;
1515
16- var meanThreshold = _createMeanThresholdOption ( ) ;
17- var allocationThreshold = _createAllocationThresholdOption ( ) ;
16+ var meanThreshold = new MeanThresholdOption ( ) ;
17+ var allocationThreshold = new AllocationThresholdOption ( ) ;
1818
19- var formats = _createFormatsOption ( ) ;
20- var output = _createOutputOption ( ) ;
19+ var formats = new FormatsOption ( ) ;
20+ var output = new OutputOption ( ) ;
2121
2222 var compareCommand = new Command (
2323 "compare" ,
@@ -43,65 +43,4 @@ public ToolCommands(IServiceProvider provider)
4343
4444 Subcommands . Add ( compareCommand ) ;
4545 }
46-
47-
48- private static Option < string > _createBaselineOption ( )
49- => new ( "--baseline" , "-b" )
50- {
51- Description = "Path to the folder or file with Baseline report." ,
52- Required = true
53- } ;
54-
55- private static Option < string > _createTargetOption ( )
56- => new ( "--target" , "-t" )
57- {
58- Description = "Path to the folder or file with target reports." ,
59- Required = true
60- } ;
61-
62- private static Option < string > _createMeanThresholdOption ( )
63- => new ( "--threshold-mean" , "-tm" )
64- {
65- Description = "Throw an error when the mean threshold is met. Examples: 5%, 10ms, 10μs, 100ns, 1s."
66- } ;
67-
68- private static Option < string > _createAllocationThresholdOption ( )
69- => new ( "--threshold-allocation" , "-ta" )
70- {
71- Description = "Throw an error when the allocation threshold is met. Examples: 5%, 10b, 10kb, 100mb, 1gb."
72- } ;
73-
74- private static Option < string [ ] > _createFormatsOption ( )
75- {
76- var option = new Option < string [ ] > ( "--format" , "-f" )
77- {
78- Description = "Output format for the report." ,
79- DefaultValueFactory = _ => [ "console" ]
80- } ;
81-
82- option . Validators . Add ( result =>
83- {
84- var allowedValues = new [ ] { "console" , "markdown" , "json" , "hit-txt" } ;
85- var values = result . GetValue ( option ) ;
86- if ( values != null )
87- {
88- foreach ( var value in values )
89- {
90- if ( ! allowedValues . Contains ( value ) )
91- {
92- result . AddError ( $ "Invalid format '{ value } '. Allowed values: { string . Join ( ", " , allowedValues ) } ") ;
93- }
94- }
95- }
96- } ) ;
97-
98- return option ;
99- }
100-
101- private static Option < string > _createOutputOption ( )
102- => new ( "--output" , "-o" )
103- {
104- Description = "Output directory to export the diff report. Default is current directory." ,
105- DefaultValueFactory = _ => "./BenchmarkReporter"
106- } ;
10746}
0 commit comments