Skip to content

Commit

Permalink
Add version switch to allow tools to easily check what version of the…
Browse files Browse the repository at this point in the history
… tool is installed.
  • Loading branch information
normj committed Feb 5, 2025
1 parent 8c1705f commit ccc13ae
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -28,6 +29,12 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
{
try
{
if (settings.PrintVersionInfo)
{
PrintVersionInfo();
return CommandReturnCodes.Success;
}

EvaluateEnvironmentVariables(settings);

if (!settings.LambdaEmulatorPort.HasValue && !settings.ApiGatewayEmulatorPort.HasValue)
Expand Down Expand Up @@ -101,6 +108,15 @@ public override async Task<int> ExecuteAsync(CommandContext context, RunCommandS
}
}

private void PrintVersionInfo()
{
Utf8JsonWriter utf8JsonWriter = new Utf8JsonWriter(Console.OpenStandardOutput());
utf8JsonWriter.WriteStartObject();
utf8JsonWriter.WriteString("version", Utilities.Utils.DetermineToolVersion());
utf8JsonWriter.WriteEndObject();
utf8JsonWriter.Flush();
}

private void EvaluateEnvironmentVariables(RunCommandSettings settings)
{
var environmentVariables = environmentManager.GetEnvironmentVariables();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -69,4 +69,11 @@ public sealed class RunCommandSettings : CommandSettings
[CommandOption("--api-gateway-emulator-port <PORT>")]
[Description("The port number used for the test tool's API Gateway emulator.")]
public int? ApiGatewayEmulatorPort { get; set; }

/// <summary>
/// When set the tool prints version information as a JSON document and then exits.
/// </summary>
[CommandOption("--version")]
[Description("When set the tool prints version information as a JSON document and then exits.")]
public bool PrintVersionInfo { get; set; }
}

0 comments on commit ccc13ae

Please sign in to comment.