diff --git a/.autover/changes/efa829ed-59af-46eb-a5e5-ef471698c82d.json b/.autover/changes/efa829ed-59af-46eb-a5e5-ef471698c82d.json
new file mode 100644
index 000000000..c05d67d65
--- /dev/null
+++ b/.autover/changes/efa829ed-59af-46eb-a5e5-ef471698c82d.json
@@ -0,0 +1,12 @@
+{
+ "Projects": [
+ {
+ "Name": "Amazon.Lambda.TestTool",
+ "Type": "Patch",
+ "ChangelogMessages": [
+ "Breaking change: Switch to use commands to invoke the tool. For example to run the Lambda emulator use the command 'dotnet lambda-test-tool start --lambda-emulator-port 5050'",
+ "Add new info command to get metadata about the tool. For example getting the version number of the tool."
+ ]
+ }
+ ]
+}
\ No newline at end of file
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs
index 2dd4395c7..232b48552 100644
--- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/RunCommand.cs
@@ -2,6 +2,7 @@
// SPDX-License-Identifier: Apache-2.0
using System.Diagnostics;
+using System.Text.Json;
using Amazon.Lambda.TestTool.Commands.Settings;
using Amazon.Lambda.TestTool.Extensions;
using Amazon.Lambda.TestTool.Models;
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs
index aac0bccb9..cdabc377a 100644
--- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/RunCommandSettings.cs
@@ -8,7 +8,7 @@
namespace Amazon.Lambda.TestTool.Commands.Settings;
///
-/// Represents the settings for configuring the , which is the default command.
+/// Represents the settings for configuring the .
///
public sealed class RunCommandSettings : CommandSettings
{
@@ -36,22 +36,6 @@ public sealed class RunCommandSettings : CommandSettings
[Description("Disable auto launching the test tool's web interface in a browser.")]
public bool NoLaunchWindow { get; set; }
- ///
- /// If set to true the test tool will pause waiting for a key input before exiting.
- /// The is useful when executing from an IDE so you can avoid having the output window immediately disappear after executing the Lambda code.
- /// The default value is true.
- ///
- [CommandOption("--pause-exit")]
- [Description("If set to true the test tool will pause waiting for a key input before exiting. The is useful when executing from an IDE so you can avoid having the output window immediately disappear after executing the Lambda code. The default value is true.")]
- public bool PauseExit { get; set; }
-
- ///
- /// Disables logging in the application
- ///
- [CommandOption("--disable-logs")]
- [Description("Disables logging in the application")]
- public bool DisableLogs { get; set; }
-
///
/// The API Gateway Emulator Mode specifies the format of the event that API Gateway sends to a Lambda integration,
/// and how API Gateway interprets the response from Lambda.
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/ToolInfoCommandSettings.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/ToolInfoCommandSettings.cs
new file mode 100644
index 000000000..22af3b720
--- /dev/null
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/ToolInfoCommandSettings.cs
@@ -0,0 +1,30 @@
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+using Amazon.Lambda.TestTool.Models;
+using Spectre.Console.Cli;
+using System.ComponentModel;
+
+namespace Amazon.Lambda.TestTool.Commands.Settings;
+
+///
+/// Represents the settings for configuring the .
+///
+public sealed class ToolInfoCommandSettings : CommandSettings
+{
+ public enum InfoFormat
+ {
+ Text,
+ Json
+ }
+
+ ///
+ /// The format the info is displayed as.
+ /// The available formats are: Text, Json.
+ ///
+ [CommandOption("--format ")]
+ [Description(
+ "The format the info is displayed as. " +
+ "The available formats are: Text, Json.")]
+ public InfoFormat? Format { get; set; }
+}
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/ToolInfoCommand.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/ToolInfoCommand.cs
new file mode 100644
index 000000000..a7a09af1b
--- /dev/null
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/ToolInfoCommand.cs
@@ -0,0 +1,81 @@
+// Copyright Amazon.com, Inc. or its affiliates. All Rights Reserved.
+// SPDX-License-Identifier: Apache-2.0
+
+using System.Text;
+using System.Text.Json;
+using Amazon.Lambda.TestTool.Commands.Settings;
+using Amazon.Lambda.TestTool.Models;
+using Amazon.Lambda.TestTool.Services;
+using Amazon.Lambda.TestTool.Utilities;
+using Spectre.Console.Cli;
+
+namespace Amazon.Lambda.TestTool.Commands;
+
+///
+/// Command to display tool information like the version of the tool.
+///
+///
+public class ToolInfoCommand(IToolInteractiveService toolInteractiveService)
+ : Command
+{
+ ///
+ /// The method responsible for executing the .
+ ///
+ public override int Execute(CommandContext context, ToolInfoCommandSettings settings)
+ {
+ var info = CollectInformation();
+
+ var formattedInfo = settings.Format switch
+ {
+ ToolInfoCommandSettings.InfoFormat.Text => GenerateToolInfoText(info),
+ ToolInfoCommandSettings.InfoFormat.Json => GenerateToolInfoJson(info),
+ _ => GenerateToolInfoText(info)
+ };
+
+ toolInteractiveService.WriteLine(formattedInfo);
+ return CommandReturnCodes.Success;
+ }
+
+ private string GenerateToolInfoText(IDictionary info)
+ {
+ var stringBuilder = new StringBuilder();
+ foreach(var kvp in info)
+ {
+ stringBuilder.AppendLine($"{kvp.Key}: {kvp.Value}");
+ }
+
+ return stringBuilder.ToString();
+ }
+
+ private string GenerateToolInfoJson(IDictionary info)
+ {
+ var stream = new MemoryStream();
+ Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(stream, options: new JsonWriterOptions()
+ {
+ Indented = false
+ });
+
+ utf8JsonWriter.WriteStartObject();
+
+ foreach (var kvp in info)
+ {
+ utf8JsonWriter.WriteString(kvp.Key, kvp.Value);
+ }
+
+ utf8JsonWriter.WriteEndObject();
+ utf8JsonWriter.Flush();
+
+ stream.Position = 0;
+ return new StreamReader(stream).ReadToEnd();
+ }
+
+ private Dictionary CollectInformation()
+ {
+ var info = new Dictionary();
+ info["Version"] = Utils.DetermineToolVersion();
+ info["InstallPath"] = GetInstallPath();
+ return info;
+ }
+
+ private string GetInstallPath() => Directory.GetParent(typeof(Utils).Assembly.Location)!.FullName;
+}
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Program.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Program.cs
index 3cbfd6b5e..4dd25fbc9 100644
--- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Program.cs
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Program.cs
@@ -13,9 +13,14 @@
var registrar = new TypeRegistrar(serviceCollection);
-var app = new CommandApp(registrar);
+var app = new CommandApp(registrar);
app.Configure(config =>
{
+ config.AddCommand("start")
+ .WithDescription("Start the Lambda and/or API Gateway emulator.");
+ config.AddCommand("info")
+ .WithDescription("Display information about the tool including the version number.");
+
config.SetApplicationName(Constants.ToolName);
});
diff --git a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Utilities/Utils.cs b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Utilities/Utils.cs
index ead444dd3..183ab47e5 100644
--- a/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Utilities/Utils.cs
+++ b/Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Utilities/Utils.cs
@@ -21,7 +21,7 @@ public static string DetermineToolVersion()
AssemblyInformationalVersionAttribute? attribute = null;
try
{
- var assembly = Assembly.GetEntryAssembly();
+ var assembly = typeof(Utils).Assembly;
if (assembly == null)
return unknownVersion;
attribute = assembly.GetCustomAttribute();
diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/RunCommandTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/RunCommandTests.cs
index d3e3e9262..b7e4f9b2f 100644
--- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/RunCommandTests.cs
+++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/RunCommandTests.cs
@@ -11,6 +11,7 @@
using Xunit;
using Amazon.Lambda.TestTool.Services.IO;
using Amazon.Lambda.TestTool.Utilities;
+using System.Text.Json.Nodes;
namespace Amazon.Lambda.TestTool.UnitTests.Commands;
@@ -100,4 +101,41 @@ public async Task ExecuteAsync_EnvPorts_SuccessfulLaunch()
Assert.Equal(CommandReturnCodes.Success, result);
Assert.True(isApiRunning);
}
+
+ [Fact]
+ public void VerifyToolInfo()
+ {
+ var writeCalls = 0;
+ string? versionInfo = null;
+ Mock mockInteractiveService = new Mock();
+ mockInteractiveService.Setup(i => i.WriteLine(It.IsAny()))
+ .Callback((string message) =>
+ {
+ writeCalls++;
+ versionInfo = message;
+ });
+
+ var settings = new ToolInfoCommandSettings { Format = ToolInfoCommandSettings.InfoFormat.Json };
+ var command = new ToolInfoCommand(mockInteractiveService.Object);
+ var context = new CommandContext(new List(), _mockRemainingArgs.Object, "run", null);
+ command.Execute(context, settings);
+
+ Assert.Equal(1, writeCalls);
+ Assert.True(!string.IsNullOrEmpty(versionInfo));
+
+ JsonNode? jsonNode = JsonNode.Parse(versionInfo);
+ Assert.NotNull(jsonNode);
+
+ var version = jsonNode["Version"]?.ToString();
+ Assert.NotNull(version);
+
+ // The Version.TryParse does not like the preview suffix
+ version = version.Replace("-preview", "");
+ Assert.True(Version.TryParse(version, out var _));
+
+ var installPath = jsonNode["InstallPath"]?.ToString();
+ Assert.NotNull(installPath);
+ Assert.True(Directory.Exists(installPath));
+ Assert.True(Path.IsPathFullyQualified(installPath));
+ }
}
diff --git a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/Settings/RunCommandSettingsTests.cs b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/Settings/RunCommandSettingsTests.cs
index b10d1caaf..4c89c36ff 100644
--- a/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/Settings/RunCommandSettingsTests.cs
+++ b/Tools/LambdaTestTool-v2/tests/Amazon.Lambda.TestTool.UnitTests/Commands/Settings/RunCommandSettingsTests.cs
@@ -28,26 +28,6 @@ public void NoLaunchWindow_DefaultsToFalse()
Assert.False(settings.NoLaunchWindow);
}
- [Fact]
- public void DisableLogs_DefaultsToFalse()
- {
- // Arrange
- var settings = new RunCommandSettings();
-
- // Assert
- Assert.False(settings.DisableLogs);
- }
-
- [Fact]
- public void PauseExit_DefaultsToFalse()
- {
- // Arrange
- var settings = new RunCommandSettings();
-
- // Assert
- Assert.False(settings.PauseExit);
- }
-
[Fact]
public void ApiGatewayEmulatorMode_DefaultsToNull()
{