@@ -16,18 +16,39 @@ internal class BillsSkill(IBillService service) : ISkill
16
16
17
17
public IEnumerable < Command > GetCommands ( )
18
18
{
19
+ var option = new Option < int > ( new string [ ] { "--months" , "-m" } , ( ) => 1 , "The number of months of bills to download." ) ;
20
+
21
+ var all = new Command ( "all" , "Download bills from all providers" )
22
+ {
23
+ option
24
+ } ;
25
+ all . Handler = CommandHandler . Create ( async ( int months ) => await DownloadAllBills ( months ) ) ;
26
+
19
27
var alectra = new Command ( "alectra" , "Download bills from Alectra" )
20
28
{
29
+ option
30
+ } ;
31
+ alectra . Handler = CommandHandler . Create ( async ( int months ) => await DownloadAlectraBills ( months ) ) ;
32
+
33
+ var enbridge = new Command ( "enbridge" , "Download bills from Enbridge" )
34
+ {
35
+ option
21
36
} ;
22
- alectra . Handler = CommandHandler . Create ( async ( ) => await DownloadAlectraBills ( ) ) ;
37
+ enbridge . Handler = CommandHandler . Create ( async ( int months ) => await DownloadEnbridgeBills ( months ) ) ;
23
38
24
39
var configure = new Command ( "configure" , "Configures the Bill provider" ) ;
25
40
configure . AddAlias ( "config" ) ;
26
41
configure . Handler = CommandHandler . Create ( ( ) => Configure ( ) ) ;
27
42
43
+ var install = new Command ( "install" , "Installs Playwright for the Bill provider" ) ;
44
+ install . Handler = CommandHandler . Create ( ( ) => _service . InstallPlaywright ( ) ) ;
45
+
28
46
var command = new Command ( "bills" , "Download bills from online" )
29
47
{
48
+ all ,
30
49
alectra ,
50
+ enbridge ,
51
+ install ,
31
52
configure
32
53
} ;
33
54
command . AddAlias ( "billing" ) ;
@@ -36,13 +57,22 @@ public IEnumerable<Command> GetCommands()
36
57
return new List < Command > { command } ;
37
58
}
38
59
39
- private async Task DownloadAlectraBills ( )
40
- {
60
+ private async Task DownloadAllBills ( int months ) =>
61
+ await DownloadBills ( ":spiral_notepad: Download Bills" , months , _service . DownloadAllBills ) ;
62
+
63
+ private async Task DownloadAlectraBills ( int months ) =>
64
+ await DownloadBills ( ":high_voltage: Alectra Bills" , months , _service . DownloadAlectraBills ) ;
65
+
66
+ private async Task DownloadEnbridgeBills ( int months ) =>
67
+ await DownloadBills ( ":chart_increasing: Enbridge Bills" , months , _service . DownloadEnbridgeBills ) ;
68
+
69
+ private static async Task DownloadBills ( string title , int months , Func < int , Task > downloader )
70
+ {
41
71
try
42
72
{
43
- AnsiConsoleHelper . TitleRule ( ":high_voltage: Alectra Bills" ) ;
73
+ AnsiConsoleHelper . TitleRule ( title ) ;
44
74
45
- await _service . DownloadAlectraBills ( ) ;
75
+ await downloader ( months ) ;
46
76
47
77
AnsiConsoleHelper . Rule ( "white" ) ;
48
78
}
0 commit comments