From c711db0d1102f6ded4374d7ea86b19f603960784 Mon Sep 17 00:00:00 2001 From: Martin Potter Date: Fri, 31 May 2024 08:01:46 -0700 Subject: [PATCH 1/2] Add CommandLineParsed to allow initialization based on arguments --- src/Faithlife.Build/BuildApp.cs | 15 +++++++++++++++ src/Faithlife.Build/BuildRunner.cs | 12 +++++++++--- 2 files changed, 24 insertions(+), 3 deletions(-) diff --git a/src/Faithlife.Build/BuildApp.cs b/src/Faithlife.Build/BuildApp.cs index e871fe7..01bc132 100644 --- a/src/Faithlife.Build/BuildApp.cs +++ b/src/Faithlife.Build/BuildApp.cs @@ -66,16 +66,31 @@ public BuildTarget Target(string name) return target; } + /// + /// Adds an action to execute when the command line arguments have been parsed, but before the target(s) are evaluated and executed. + /// + /// The action to execute when the command line arguments have been parsed. + public void CommandLineParsed(Action action) + { + ArgumentNullException.ThrowIfNull(action); + + m_commandLineParsedActions.Add(action); + } + internal BuildApp(CommandLineApplication app) { m_app = app; m_targets = new List(); m_flags = new List(); m_options = new List(); + m_commandLineParsedActions = new List(); } + internal IReadOnlyList CommandLineParsedActions => m_commandLineParsedActions; + private readonly CommandLineApplication m_app; private readonly List m_targets; private readonly List m_flags; private readonly List m_options; + private readonly List m_commandLineParsedActions; } diff --git a/src/Faithlife.Build/BuildRunner.cs b/src/Faithlife.Build/BuildRunner.cs index 421f72e..c289d8d 100644 --- a/src/Faithlife.Build/BuildRunner.cs +++ b/src/Faithlife.Build/BuildRunner.cs @@ -60,12 +60,18 @@ public static async Task ExecuteAsync(string[] args, Action initi var helpFlag = buildApp.AddFlag("-h|-?|--help", "Show build help"); var targetsArgument = commandLineApp.Argument("targets", "The targets to build", multipleValues: true); - var bullseyeTargets = new Targets(); - foreach (var target in buildApp.Targets) - bullseyeTargets.Add(name: target.Name, description: target.Description, dependsOn: target.Dependencies, action: target.RunAsync); + commandLineApp.OnParsingComplete(_ => + { + foreach (var commandLineParsedAction in buildApp.CommandLineParsedActions) + commandLineParsedAction(); + }); commandLineApp.OnExecuteAsync(async _ => { + var bullseyeTargets = new Targets(); + foreach (var target in buildApp.Targets) + bullseyeTargets.Add(name: target.Name, description: target.Description, dependsOn: target.Dependencies, action: target.RunAsync); + var targetNames = targetsArgument.Values.WhereNotNull().ToList(); if (targetNames.Count == 0 && buildApp.Targets.Any(x => x.Name == c_defaultTarget)) From 600c65b07db3d807abd079426bc9ad8fbd1ab188 Mon Sep 17 00:00:00 2001 From: Martin Potter Date: Fri, 31 May 2024 09:31:04 -0700 Subject: [PATCH 2/2] Publish 5.21.0. --- Directory.Build.props | 2 +- ReleaseNotes.md | 4 ++++ 2 files changed, 5 insertions(+), 1 deletion(-) diff --git a/Directory.Build.props b/Directory.Build.props index 88f901e..a472fa3 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,7 +1,7 @@ - 5.20.2 + 5.21.0 5.19.1 12.0 enable diff --git a/ReleaseNotes.md b/ReleaseNotes.md index 0c231e4..f8d3819 100644 --- a/ReleaseNotes.md +++ b/ReleaseNotes.md @@ -1,5 +1,9 @@ # Release Notes +## 5.21.0 + +* Add `BuildApp.CommandLineParsed` to allow initialization based on arguments. + ## 5.20.2 * Support `VersionOverride` with `DotNetClassicTool.TryCreateFrom`.