-
Notifications
You must be signed in to change notification settings - Fork 418
Open
Description
Hello,
I've recently ported my app from some 2-beta version to 2.0.3 and it just doesn't work at all.
Ignoring my frustration please check the example code, that is in docs:
public class Class1
{
public static int Main(string[] args)
{
var cs = new CmdCrawlerSettings(args);
Argument<string?> anyArgument = new Argument<string?>("--arg")
{
Description = "whatever",
};
Option<FileInfo> fileOption = new("--file")
{
Description = "The file to read and display on the console"
};
RootCommand rootCommand = new("Sample app for System.CommandLine");
rootCommand.Arguments.Add(anyArgument);
rootCommand.Options.Add(fileOption);
var parseResult = rootCommand.Parse(args);
if (parseResult.Errors.Count == 0)
{
Console.WriteLine(parseResult);
Console.WriteLine(parseResult.GetValue(anyArgument));
Console.WriteLine(parseResult.GetValue(fileOption));
return 0;
}
foreach (var parseError in parseResult.Errors)
{
Console.Error.WriteLine(parseError.Message);
}
return 1;
}
}
nothing fancy, lets run a test:
D:/Repo/Local/C#/TestCmd/testcmd/testcmd/bin/Debug/net9.0/testcmd.exe arg --file arg1
Unrecognized command or argument '--file'.
Unrecognized command or argument 'arg1'.
Unhandled exception. System.ArgumentException: Invalid command line arguments.
at testcmd.CmdCrawlerSettings.Parse(String[] args) in D:\Repo\Local\C#\TestCmd\testcmd\testcmd\Class1.cs:line 132
at testcmd.CmdCrawlerSettings..ctor(String[] args) in D:\Repo\Local\C#\TestCmd\testcmd\testcmd\Class1.cs:line 123
at testcmd.Class1.Main(String[] args) in D:\Repo\Local\C#\TestCmd\testcmd\testcmd\Class1.cs:line 10
so test fail.
so, lets try "help":
D:/Repo/Local/C#/TestCmd/testcmd/testcmd/bin/Debug/net9.0/testcmd.exe --help
[ testcmd [ --help ] <> ]
Unhandled exception. System.InvalidOperationException: Required argument missing for command: 'testcmd'.
at System.CommandLine.Binding.ArgumentConverter.GetValueOrDefault[T](ArgumentConversionResult result)
at System.CommandLine.Parsing.ArgumentResult.GetValueOrDefault[T]()
at System.CommandLine.Parsing.SymbolResult.GetValue[T](Argument`1 argument)
at System.CommandLine.ParseResult.GetValue[T](Argument`1 argument)
at testcmd.Class1.Main(String[] args) in D:\Repo\Local\C#\TestCmd\testcmd\testcmd\Class1.cs:line 30
another fail.
csproj for ref:
<Project Sdk="Microsoft.NET.Sdk">
<PropertyGroup>
<TargetFramework>net9.0</TargetFramework>
<LangVersion>latest</LangVersion>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<OutputType>Exe</OutputType>
</PropertyGroup>
<ItemGroup>
<PackageReference Include="System.CommandLine" Version="2.0.3" />
</ItemGroup>
</Project>
I am assuming I am doing something wrong. Could anybody be so kind to point me what?
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels