Skip to content

Commit

Permalink
inject parser into constructor rather than method
Browse files Browse the repository at this point in the history
  • Loading branch information
gord5500 committed Jun 29, 2023
1 parent f0cd054 commit aa525c6
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 13 deletions.
6 changes: 3 additions & 3 deletions src/D2L.Bmx/BmxConfigProvider.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,10 +8,10 @@ namespace D2L.Bmx;

internal interface IBmxConfigProvider {
BmxConfig GetConfiguration();
void SaveConfiguration( BmxConfig config, FileIniDataParser parser );
void SaveConfiguration( BmxConfig config );
}

internal class BmxConfigProvider : IBmxConfigProvider {
internal class BmxConfigProvider( FileIniDataParser parser ) : IBmxConfigProvider {
public BmxConfig GetConfiguration() {
// Main config is at ~/.bmx/config
string configFileName = BmxPaths.CONFIG_FILE_NAME;
Expand Down Expand Up @@ -49,7 +49,7 @@ public BmxConfig GetConfiguration() {
);
}

public void SaveConfiguration( BmxConfig config, FileIniDataParser parser ) {
public void SaveConfiguration( BmxConfig config ) {
if( !Directory.Exists( BmxPaths.BMX_DIR ) ) {
Directory.CreateDirectory( BmxPaths.BMX_DIR );
}
Expand Down
6 changes: 2 additions & 4 deletions src/D2L.Bmx/ConfigureHandler.cs
Original file line number Diff line number Diff line change
@@ -1,11 +1,9 @@
using IniParser;

namespace D2L.Bmx;

internal class ConfigureHandler(
IBmxConfigProvider configProvider,
IConsolePrompter consolePrompter,
FileIniDataParser parser
IConsolePrompter consolePrompter
) {
public void Handle(
string? org,
Expand Down Expand Up @@ -34,7 +32,7 @@ bool nonInteractive
Profile: null,
Duration: duration
);
configProvider.SaveConfiguration( config, parser );
configProvider.SaveConfiguration( config );
Console.WriteLine( "Your configuration has been created. Okta sessions will now also be cached." );
}
}
11 changes: 5 additions & 6 deletions src/D2L.Bmx/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -39,9 +39,8 @@

configureCommand.SetHandler( ( InvocationContext context ) => RunWithErrorHandlingAsync( context, () => {
var handler = new ConfigureHandler(
new BmxConfigProvider(),
new ConsolePrompter(),
new FileIniDataParser() );
new BmxConfigProvider( new FileIniDataParser() ),
new ConsolePrompter() );
handler.Handle(
org: context.ParseResult.GetValueForOption( orgOption ),
user: context.ParseResult.GetValueForOption( userOption ),
Expand Down Expand Up @@ -88,7 +87,7 @@

printCommand.SetHandler( ( InvocationContext context ) => RunWithErrorHandlingAsync( context, () => {
var consolePrompter = new ConsolePrompter();
var config = new BmxConfigProvider().GetConfiguration();
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var handler = new PrintHandler(
new OktaAuthenticator(
new OktaApi(),
Expand Down Expand Up @@ -134,7 +133,7 @@

writeCommand.SetHandler( ( InvocationContext context ) => RunWithErrorHandlingAsync( context, () => {
var consolePrompter = new ConsolePrompter();
var config = new BmxConfigProvider().GetConfiguration();
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var handler = new WriteHandler(
new OktaAuthenticator(
new OktaApi(),
Expand Down Expand Up @@ -170,7 +169,7 @@

loginCommand.SetHandler( ( InvocationContext context ) => RunWithErrorHandlingAsync( context, () => {
var consolePrompter = new ConsolePrompter();
var config = new BmxConfigProvider().GetConfiguration();
var config = new BmxConfigProvider( new FileIniDataParser() ).GetConfiguration();
var handler = new LoginHandler(
new OktaAuthenticator(
new OktaApi(),
Expand Down

0 comments on commit aa525c6

Please sign in to comment.