Skip to content
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

Add --print-tool-path CLI arguments to simplify IDE debug configuration #1456

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
20 changes: 20 additions & 0 deletions Tools/LambdaTestTool/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -83,6 +83,7 @@ using the commandline switches as described below. To switch to the no web inter
These options are valid for either mode the Lambda test tool is running in.

--path <directory> The path to the lambda project to execute. If not set then the current directory will be used.
--print-tool-path <vs|vscode|other> Printing the .NET Lambda Test Tool location path to be inserted in the IDE."

These options are valid when using the web interface to select and execute the Lambda code.

Expand Down Expand Up @@ -157,6 +158,12 @@ Before using Visual Studio Code you must follow the instructions above on instal

To debug with Visual Studio Code and the .NET Mock Lambda Test Tool edit the [launch.json](https://code.visualstudio.com/docs/editor/debugging#_launch-configurations) configuration file and have the `program` property point to `dotnet-lambda-test-tool-3.1.exe` and make sure `cwd` is pointing the .NET Core Lambda project. Note that on a non-windows environment the executable will be called `dotnet-lambda-test-tool-3.1` without the ".exe" at the end. The `dotnet-lambda-test-tool-3.1.exe` executable can be found in the `.dotnet/tools` directory under your home directory. Depending on your file system settings, the `.dotnet` directory can appear hidden.

**Note:** to make it easier to find the location of a tool, you can call it with the arguments `--print-tool-path` and copy the resulting path into the IDE.

```
dotnet lambda-test-tool-3.1 --print-tool-path vscode
```

```json
{
"version": "0.2.0",
Expand Down Expand Up @@ -195,6 +202,12 @@ The path to the .NET Core 3.1 entry assembly is:
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-3.1/<nuget-version>/amazon.lambda.testtool-3.1/<nuget-version>/tools/netcoreapp3.1/any/Amazon.Lambda.TestTool.WebTester31.dll
```

**Note:** to make it easier to find the location of a tool, you can call it with the arguments `--print-tool-path` and
copy the resulting path into the IDE.

```
dotnet lambda-test-tool-3.1 --print-tool-path other
```

Remember when you update your version of the .NET Mock Lambda Test Tool to update the nuget versions numbers in this path string for your IDE's configuration.

Expand Down Expand Up @@ -223,6 +236,13 @@ The path to the .NET Core 3.1 entry assembly is:
<home-directory>/.dotnet/tools/.store/amazon.lambda.testtool-3.1/<nuget-version>/amazon.lambda.testtool-3.1/<nuget-version>/tools/netcoreapp3.1/any/Amazon.Lambda.TestTool.WebTester31.dll
```

**Note:** to make it easier to find the location of a tool, you can call it with the arguments `--print-tool-path` and
copy the resulting path into the IDE.

```
dotnet lambda-test-tool-3.1 --print-tool-path other
```

Remember when you update your version of the .NET Mock Lambda Test Tool to update the nuget versions numbers in this path string for your IDE's configuration.

Follow these steps to configure Visual Studio for Mac:
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,6 +26,8 @@ public class CommandLineOptions

public bool ShowHelp { get; set; }

public string PrintToolPathIde { get; set; }

public bool PauseExit { get; set; } = true;

public static CommandLineOptions Parse(string[] args)
Expand All @@ -43,6 +45,11 @@ public static CommandLineOptions Parse(string[] args)
{
i++;
}
break;
case "--print-tool-path":
options.PrintToolPathIde = GetNextStringValue(i);
i++;

break;
case "--host":
options.Host = GetNextStringValue(i);
Expand Down Expand Up @@ -145,6 +152,7 @@ public static void PrintUsage()
Console.WriteLine("These options are valid for either mode the Lambda test tool is running in.");
Console.WriteLine();
Console.WriteLine("\t--path <directory> The path to the lambda project to execute. If not set then the current directory will be used.");
Console.WriteLine("\t--print-tool-path <vs|vscode|other> Printing the .NET Lambda Test Tool location path to be inserted in the IDE.");
Console.WriteLine();

Console.WriteLine("These options are valid when using the web interface to select and execute the Lambda code.");
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,12 @@ public static void Startup(string productName, Action<LocalLambdaOptions, bool>
return;
}

if (!string.IsNullOrEmpty(commandOptions.PrintToolPathIde))
{
Console.WriteLine(Utils.GetToolPath(commandOptions.PrintToolPathIde));
return;
}

var localLambdaOptions = new LocalLambdaOptions()
{
Host = commandOptions.Host,
Expand Down
16 changes: 16 additions & 0 deletions Tools/LambdaTestTool/src/Amazon.Lambda.TestTool/Utils.cs
Original file line number Diff line number Diff line change
Expand Up @@ -241,5 +241,21 @@ public static string SearchLatestCompilationDirectory(string debugDirectory)

return depsFile[0].Directory.FullName;
}

/// <summary>
/// Return tool path compatible with specific IDE for debug purposes
/// </summary>
/// <param name="ideName"></param>
/// <returns></returns>
public static string GetToolPath(string ideName)
{
ideName = ideName.Trim().ToLower();
if (ideName == "vs" || ideName == "vscode")
{
return Process.GetCurrentProcess().MainModule!.FileName;
}

return Assembly.GetEntryAssembly()!.Location;
}
}
}