Skip to content

Commit

Permalink
fixing a couple other things
Browse files Browse the repository at this point in the history
  • Loading branch information
belav committed Jun 2, 2024
1 parent e5ff79e commit e300a8f
Show file tree
Hide file tree
Showing 3 changed files with 14 additions and 23 deletions.
7 changes: 1 addition & 6 deletions Src/CSharpier.Cli/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -56,12 +56,7 @@ CancellationToken cancellationToken

if (server)
{
return await ServerFormatter.StartServer(
serverPort,
logger,
actualConfigPath,
cancellationToken
);
return await ServerFormatter.StartServer(serverPort, logger, actualConfigPath);
}

var directoryOrFileNotProvided = directoryOrFile is null or { Length: 0 };
Expand Down
19 changes: 6 additions & 13 deletions Src/CSharpier.Cli/Server/CSharpierServiceImplementation.cs
Original file line number Diff line number Diff line change
Expand Up @@ -2,19 +2,11 @@ namespace CSharpier.Cli.Server;

using System.IO.Abstractions;
using CSharpier.Cli.Options;
using Microsoft.Extensions.Logging;

internal class CSharpierServiceImplementation
internal class CSharpierServiceImplementation(string? configPath, ILogger logger)
{
private readonly string? configPath;
private readonly IFileSystem fileSystem;
private readonly ConsoleLogger logger;

public CSharpierServiceImplementation(string? configPath, ConsoleLogger logger)
{
this.configPath = configPath;
this.logger = logger;
this.fileSystem = new FileSystem();
}
private readonly IFileSystem fileSystem = new FileSystem();

public async Task<FormatFileResult> FormatFile(
FormatFileParameter formatFileParameter,
Expand All @@ -23,6 +15,7 @@ CancellationToken cancellationToken
{
try
{
logger.LogInformation("Received request to format " + formatFileParameter.fileName);
var directoryName = this.fileSystem.Path.GetDirectoryName(formatFileParameter.fileName);
DebugLogger.Log(directoryName ?? string.Empty);
if (directoryName == null)
Expand All @@ -34,9 +27,9 @@ CancellationToken cancellationToken

var optionsProvider = await OptionsProvider.Create(
directoryName,
this.configPath,
configPath,
this.fileSystem,
this.logger,
logger,
cancellationToken
);

Expand Down
11 changes: 7 additions & 4 deletions Src/CSharpier.Cli/Server/ServerFormatter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,14 @@ internal static class ServerFormatter
public static async Task<int> StartServer(
int? port,
ConsoleLogger logger,
string? actualConfigPath,
CancellationToken cancellationToken
string? actualConfigPath
)
{
var builder = WebApplication.CreateBuilder();
builder.WebHost.ConfigureKestrel(
(_, serverOptions) =>
{
serverOptions.Listen(IPAddress.Loopback, 0);
serverOptions.Listen(IPAddress.Loopback, port ?? 0);
}
);
builder.Logging.ClearProviders();
Expand Down Expand Up @@ -54,7 +53,11 @@ var address in (app as IApplicationBuilder)
logger.LogInformation("Started on " + uri.Port);
}
});
var service = new CSharpierServiceImplementation(actualConfigPath, logger);
var service = new CSharpierServiceImplementation(
actualConfigPath,
// we want any further logging to happen in the file log, not out to the console
app.Services.GetRequiredService<ILogger<CSharpierServiceImplementation>>()
);
app.MapPost(
"/format",
(FormatFileParameter formatFileDto, CancellationToken cancellationToken) =>
Expand Down

0 comments on commit e300a8f

Please sign in to comment.