Skip to content

Commit

Permalink
Adds several UX imporvments
Browse files Browse the repository at this point in the history
  • Loading branch information
PascalSenn committed Aug 22, 2023
1 parent 7459f3e commit 4b3109c
Show file tree
Hide file tree
Showing 12 changed files with 68 additions and 127 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -90,9 +90,14 @@ public async Task<int> ExecuteAsync(CancellationToken cancellationToken)
Services = _services
};

await _pipeline(context);

await status.StopAsync();
try
{
await _pipeline(context);
}
finally
{
await status.StopAsync();
}

return context.ExitCode;
}
Expand All @@ -104,9 +109,10 @@ public async Task<int> ExecuteAsync(CancellationToken cancellationToken)

public ValueTask<IAsyncDisposable> PauseAsync(CancellationToken cancellationToken)
=> ValueTask.FromResult<IAsyncDisposable>(this);

public ValueTask StopAsync() => ValueTask.CompletedTask;

/// <inheritdoc />
public ValueTask DisposeAsync()
=> ValueTask.CompletedTask;
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,8 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex
var configuration = context.Features.Get<ConfigurationFeature>();
if (!configuration.TryGetSolution(out var solutionFile))
{
context.Logger.NoSolutionFileFound();
throw new ExitException();
throw new ExitException(
"No solution file found, could not load VSCode Settings. Please make sure that the current directory is a Confix solution.");
}

await next(context);
Expand All @@ -45,15 +45,6 @@ public async Task InvokeAsync(IMiddlewareContext context, MiddlewareDelegate nex
}
}

file static class Logs
{
public static void NoSolutionFileFound(this IConsoleLogger logger)
{
logger.Error(
"No solution file found, could not load VSCode Settings. Please make sure that the current directory is a Confix solution.");
}
}

file static class Extensions
{
public static bool TryGetSolution(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,7 @@ public IReadOnlyList<ConfigurationFile> GetConfigurationFiles(IConfigurationFile
var configuration =
AppSettingsConfigurationFileProviderConfiguration.Parse(context.Definition.Value);

var input = context.Project.Directory!.FindInPath(FileNames.AppSettings, false);

if (input is null)
if (context.Project.Directory?.FindInPath(FileNames.AppSettings, false) is not { } input)
{
return Array.Empty<ConfigurationFile>();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -10,11 +10,16 @@ public sealed class InlineConfigurationFileProvider : IConfigurationFileProvider

public IReadOnlyList<ConfigurationFile> GetConfigurationFiles(IConfigurationFileContext context)
{
var files = new List<ConfigurationFile>();

var path = context.Definition.Value.ExpectValue<string>();

foreach (var file in context.Project.Directory!.FindAllInPath(path, false))
if (context.Project.Directory is not { } directory)
{
return Array.Empty<ConfigurationFile>();
}

var files = new List<ConfigurationFile>();

foreach (var file in directory.FindAllInPath(path, false))
{
context.Logger.FoundAInlineConfigurationFile(file);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,8 @@ public async Task ExecuteAsync(IComponentProviderContext context)
var buildResult = await DotnetHelpers.BuildProjectAsync(csproj, context.CancellationToken);
if (!buildResult.Succeeded)
{
context.Logger.DotnetProjectBuildFailed(buildResult.Output);
throw new ExitException();
var output = buildResult.Output.EscapeMarkup();
throw new ExitException($"Failed to build project:\n{output}");
}

var projectAssembly = DotnetHelpers.GetAssemblyFileFromCsproj(csproj);
Expand Down Expand Up @@ -277,9 +277,4 @@ public static void ParsingComponent(
logger.Debug(
$"Parsing component from resource '{resourceName}' in assembly '{assembly.FullName}'");
}

public static void DotnetProjectBuildFailed(this IConsoleLogger logger, string output)
{
logger.Error($"Failed to build project:\n{output.EscapeMarkup()}");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -35,8 +35,9 @@ private static async Task InvokeAsync(IMiddlewareContext context)

if (componentFile.Exists)
{
context.Logger.LogComponentAlreadyExists(componentFile);
throw new ExitException();
var link = componentFile.Directory?.Name.ToLink(componentFile);
throw new ExitException(
$"Component already exists:{link} [dim]{componentFile.FullName}[/]");
}

await File
Expand All @@ -47,19 +48,11 @@ await File

file static class Log
{
public static void LogComponentAlreadyExists(
this IConsoleLogger console,
FileInfo info)
{
console.Error(
$"Component already exists:{info.Directory?.Name.ToLink(info)} [dim]{info.FullName}[/]");
}

public static void LogComponentCreated(
this IConsoleLogger console,
FileInfo info)
{
console.Information(
$"Component created:{info.Directory?.Name.ToLink(info)} [dim]{info.FullName}[/]");
}
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -28,9 +28,9 @@ private static async Task InvokeAsync(IMiddlewareContext context)
switch (configuration.Scope)
{
case ConfigurationScope.None:
context.Logger
.LogNoConfixContextWasFound(context.Execution.CurrentDirectory.FullName);
throw new ExitException();
var directory = context.Execution.CurrentDirectory.FullName;
throw new ExitException(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");

case ConfigurationScope.Component:
{
Expand Down Expand Up @@ -70,14 +70,3 @@ private static async Task InvokeAsync(IMiddlewareContext context)
}
}
}

file static class Log
{
public static void LogNoConfixContextWasFound(
this IConsoleLogger console,
string directory)
{
console.Error(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ private static async Task InvokeAsync(IMiddlewareContext context)
switch (configuration.Scope)
{
case ConfigurationScope.None:
context.Logger
.LogNoConfixContextWasFound(context.Execution.CurrentDirectory.FullName);
throw new ExitException();
var directory = context.Execution.CurrentDirectory.FullName;
throw new ExitException(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");

case ConfigurationScope.Component:
App.Log.ComponentsDoNotSupportReload();
throw new ExitException();
throw new ExitException(
"Components do not support reload. `reload` only works for projects and solutions.");

case ConfigurationScope.Project:
{
Expand Down Expand Up @@ -63,20 +63,3 @@ private static async Task InvokeAsync(IMiddlewareContext context)
}
}
}

file static class Log
{
public static void LogNoConfixContextWasFound(
this IConsoleLogger console,
string directory)
{
console.Error(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");
}

public static void ComponentsDoNotSupportReload(this IConsoleLogger console)
{
console.Error(
"Components do not support reload. `reload` only works for projects and solutions.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -22,8 +22,9 @@ private static async Task InvokeAsync(IMiddlewareContext context)

if (solutionFile.Exists)
{
context.Logger.LogSolutionAlreadyExists(solutionFile);
throw new ExitException();
var info = solutionFile.Directory?.Name.ToLink(solutionFile);
throw new ExitException(
$"Solution already exists: {info} [dim]{solutionFile.FullName}[/]");
}

await File.WriteAllTextAsync(solutionFile.FullName, "{}");
Expand All @@ -33,14 +34,6 @@ private static async Task InvokeAsync(IMiddlewareContext context)

file static class Log
{
public static void LogSolutionAlreadyExists(
this IConsoleLogger console,
FileInfo info)
{
console.Error(
$"Solution already exists: {info.Directory?.Name.ToLink(info)} [dim]{info.FullName}[/]");
}

public static void LogSolutionCreated(
this IConsoleLogger console,
FileInfo info)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,13 @@ private static async Task InvokeAsync(IMiddlewareContext context)
switch (configuration.Scope)
{
case ConfigurationScope.None:
context.Logger
.LogNoConfixContextWasFound(context.Execution.CurrentDirectory.FullName);
throw new ExitException();
var directory = context.Execution.CurrentDirectory.FullName;
throw new ExitException(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");

case ConfigurationScope.Component:
App.Log.ComponentsDoNotSupportValidate();
throw new ExitException();
throw new ExitException(
"Components do not support reload. `reload` only works for projects and solutions.");

case ConfigurationScope.Project:
{
Expand Down Expand Up @@ -63,20 +63,3 @@ private static async Task InvokeAsync(IMiddlewareContext context)
}
}
}

file static class Log
{
public static void LogNoConfixContextWasFound(
this IConsoleLogger console,
string directory)
{
console.Error(
$"No confix context was found in the executing directory: [yellow]{directory}[/]");
}

public static void ComponentsDoNotSupportValidate(this IConsoleLogger console)
{
console.Error(
"Components do not support reload. `reload` only works for projects and solutions.");
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -2,10 +2,6 @@ namespace Confix.Tool;

internal sealed class ExitException : Exception
{
public ExitException()
{
}

public ExitException(string message)
: base(message)
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,30 +3,39 @@ namespace Confix.Tool.Commands.Temp;
public static class DirectoryExtensions
{
public static FileInfo? FindInPath(
this DirectoryInfo directory,
this DirectoryInfo? directory,
string fileName,
bool recursive = true)
=> Directory
.EnumerateFiles(
directory.FullName,
fileName,
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
.FirstOrDefault();
=> directory is not null
? Directory
.EnumerateFiles(
directory.FullName,
fileName,
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
.FirstOrDefault()
: null;

public static IEnumerable<FileInfo> FindAllInPath(
this DirectoryInfo directory,
this DirectoryInfo? directory,
string pattern,
bool recursive = true)
=> Directory
.EnumerateFiles(
directory.FullName,
pattern,
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x));
=> directory is not null
? Directory
.EnumerateFiles(
directory.FullName,
pattern,
recursive ? SearchOption.AllDirectories : SearchOption.TopDirectoryOnly)
.Select(x => new FileInfo(x))
: Array.Empty<FileInfo>();

public static string? FindInTree(this DirectoryInfo directory, string fileName)
public static string? FindInTree(this DirectoryInfo? directory, string fileName)
{
if (directory is null)
{
return null;
}

if (!directory.Exists)
{
throw new DirectoryNotFoundException($"The directory '{directory}' was not found.");
Expand Down

0 comments on commit 4b3109c

Please sign in to comment.