This repository has been archived on 2023-02-02. You can view files and clone it, but cannot push or open issues or pull requests.
mfgames-nitride-cil/src/MfGames.Nitride/Commands/BuildCommand.cs
D. Moonfire 9e93eb6ce6 refactor!: fixed missed namespaces
- reformatted code and cleaned up references
2023-01-14 18:19:42 -06:00

71 lines
2 KiB
C#

using System.Collections.Generic;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.Threading.Tasks;
using MfGames.Nitride.Pipelines;
using Serilog;
namespace MfGames.Nitride.Commands;
/// <summary>
/// The basic command to generate a website and run through the pipelines.
/// </summary>
public class BuildCommand : Command, ICommandHandler
{
private readonly ILogger logger;
private readonly IList<IPipelineCommandOption> pipelineOptions;
private readonly PipelineManager pipelines;
public BuildCommand(
ILogger logger,
PipelineManager pipelines,
IList<IPipelineCommandOption> pipelineOptions)
: base("build", "Generate the website")
{
// Set up our simple member variables.
this.pipelines = pipelines;
this.pipelineOptions = pipelineOptions;
this.logger = logger.ForContext<BuildCommand>();
this.Handler = this;
// Handle any injected arguments into the command line.
foreach (IPipelineCommandOption? option in pipelineOptions)
{
this.AddOption(option.Option);
}
}
/// <inheritdoc />
public int Invoke(InvocationContext context)
{
return this.InvokeAsync(context).Result;
}
/// <inheritdoc />
public async Task<int> InvokeAsync(InvocationContext context)
{
// Process any injected options.
this.logger.Debug(
"Processing {Count:N0} pipeline options",
this.pipelineOptions.Count);
foreach (IPipelineCommandOption? option in this.pipelineOptions)
{
this.logger.Verbose("Processing pipeline option: {Option}", option);
option.Handle(context);
}
// This is the main entry point into the `build` command. This runs
// all the pipelines once and then quits when it finishes.
this.logger.Information("Running pipelines");
int pipelinesResults = await this.pipelines.RunAsync();
return pipelinesResults;
}
}