diff --git a/src/Faithlife.Build/BuildApp.cs b/src/Faithlife.Build/BuildApp.cs
index e871fe7..2261adb 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 commandLineParsed)
+ {
+ ArgumentNullException.ThrowIfNull(commandLineParsed);
+
+ m_commandLineParsedActions.Add(commandLineParsed);
+ }
+
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..c7ba56f 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(buildApp);
+ });
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))