-
Notifications
You must be signed in to change notification settings - Fork 490
Add version to test tool #1969
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
Merged
Add version to test tool #1969
Changes from all commits
Commits
Show all changes
5 commits
Select commit
Hold shift + click to select a range
e992386
Add version switch to allow tools to easily check what version of the…
normj 0885b62
Add unit test
normj 1293a93
Rename --version to --tool-info
normj 5aced83
Address PR comments by converting to use commands.
normj 1efc6bd
Update change file
normj File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
12 changes: 12 additions & 0 deletions
12
.autover/changes/efa829ed-59af-46eb-a5e5-ef471698c82d.json
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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." | ||
] | ||
} | ||
] | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
30 changes: 30 additions & 0 deletions
30
...LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/Settings/ToolInfoCommandSettings.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// Represents the settings for configuring the <see cref="ToolInfoCommand"/>. | ||
/// </summary> | ||
public sealed class ToolInfoCommandSettings : CommandSettings | ||
{ | ||
public enum InfoFormat | ||
{ | ||
Text, | ||
Json | ||
} | ||
|
||
/// <summary> | ||
/// The format the info is displayed as. | ||
/// The available formats are: Text, Json. | ||
/// </summary> | ||
[CommandOption("--format <FORMAT>")] | ||
[Description( | ||
"The format the info is displayed as. " + | ||
"The available formats are: Text, Json.")] | ||
public InfoFormat? Format { get; set; } | ||
} |
81 changes: 81 additions & 0 deletions
81
Tools/LambdaTestTool-v2/src/Amazon.Lambda.TestTool/Commands/ToolInfoCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -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; | ||
|
||
/// <summary> | ||
/// Command to display tool information like the version of the tool. | ||
/// </summary> | ||
/// <param name="toolInteractiveService"></param> | ||
public class ToolInfoCommand(IToolInteractiveService toolInteractiveService) | ||
: Command<ToolInfoCommandSettings> | ||
{ | ||
/// <summary> | ||
/// The method responsible for executing the <see cref="RunCommand"/>. | ||
/// </summary> | ||
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<string, string> info) | ||
{ | ||
var stringBuilder = new StringBuilder(); | ||
foreach(var kvp in info) | ||
{ | ||
stringBuilder.AppendLine($"{kvp.Key}: {kvp.Value}"); | ||
} | ||
|
||
return stringBuilder.ToString(); | ||
} | ||
|
||
private string GenerateToolInfoJson(IDictionary<string, string> 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<string, string> CollectInformation() | ||
{ | ||
var info = new Dictionary<string, string>(); | ||
info["Version"] = Utils.DetermineToolVersion(); | ||
info["InstallPath"] = GetInstallPath(); | ||
return info; | ||
} | ||
|
||
private string GetInstallPath() => Directory.GetParent(typeof(Utils).Assembly.Location)!.FullName; | ||
} |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
These were leftover from the old version of the tooling and are not used in the new version.