Open dpokluda opened 4 years ago
Can you provide a code sample that reproduces the issue?
What exactly do you want to see. Here is my simple Program.cs
:
using System;
using System.CommandLine;
using System.CommandLine.Invocation;
using System.IO;
namespace Test
{
class Program
{
static int Main(string[] args)
{
var rootCommand = new RootCommand("Simple command line tool.");
rootCommand.AddOption(new Option("--int-option", "Integer value option.") {Argument = new Argument<int>()});
rootCommand.AddOption(new Option("--bool-option", "Boolean value option.") {Argument = new Argument<bool>()});
rootCommand.AddOption(new Option("--file-option", "FileInfo value option.") {Argument = new Argument<FileInfo>()});
rootCommand.Handler = CommandHandler.Create<int, bool, FileInfo>((intOption, boolOption, fileOption) =>
{
Console.WriteLine($"IntOption: {intOption}");
Console.WriteLine($"BoolOption: {boolOption}");
Console.WriteLine($"FileOption: {fileOption}");
});
return rootCommand.InvokeAsync(args).Result;
}
}
}
Here is my CSPROJ
:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<OutputType>Exe</OutputType>
<TargetFramework>netcoreapp3.1</TargetFramework>
<AssemblyName>Test</AssemblyName>
<RootNamespace>Test</RootNamespace>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.0-beta1.20071.2" />
</ItemGroup>
</Project>
Here is content of my Microsoft.PowerShell_profile.ps1
file:
# dotnet suggest shell start
$availableToComplete = (dotnet-suggest list) | Out-String
$availableToCompleteArray = $availableToComplete.Split([Environment]::NewLine, [System.StringSplitOptions]::RemoveEmptyEntries)
Register-ArgumentCompleter -Native -CommandName $availableToCompleteArray -ScriptBlock {
param($commandName, $wordToComplete, $cursorPosition)
$fullpath = (Get-Command $wordToComplete.CommandElements[0]).Source
$arguments = $wordToComplete.Extent.ToString().Replace('"', '\"')
dotnet-suggest get -e $fullpath --position $cursorPosition -- "$arguments" | ForEach-Object {
[System.Management.Automation.CompletionResult]::new($_, $_, 'ParameterValue', $_)
}
}
$env:DOTNET_SUGGEST_SCRIPT_VERSION = "1.0.0"
# dotnet suggest script end
Is this what you have asked for? Is there anything else?
That's great, thanks!
If you run the following, do you see your app's name in the output?
> dotnet suggest list
Yes:
> dotnet suggest list
dotnet-suggest
dotnet suggest
Test
I got it working now. Let me investigate why it didn't work before. It might be related to using CmdEr.
Thank you very much for helping me.
The app is supposed to self-register but it might not work if the first time it's ever executed is for a suggest request.
You are right. It doesn't work the first time. When I close command line and restart it, then it works the second time. Is that expected behavior?
Nope, that's a bug. We don't have an issue open for it yet. Would you like to rename this one to be more specific and we can use this to track a fix?
Done. Thanks.
Just to clarify, I think this only affects the first use of a given app built with System.CommandLine
, and is unrelated to the shell / terminal needing to be restarted. It should continue to work after that, unless I'm misunderstanding.
I did follow steps for dotnet-suggest:
I am trying to get Tab completion to work but I never see any suggestion. Are they any other requirements? I have a
I build .NET Core 3.1 console application called Test using "System.CommandLine" version "2.0.0-beta1.20071.2" (configured options are --int-option, --bool-option and --file-option). When I press Tab in the following PowerShell command line nothing happens:
PS> Test.exe --int<TAB>
When I press Tab in the following PowerShell command line I just see standard PowerShell completion (files from the same directory):
PS> Test.exe <TAB>
I am sure there is something obvious that I missing. Could you please point in the right direction to get the tab completion/suggestion to work for my CommandLine console tools?