How to convert beta4 code to beta5 when parseResult.GetValue() may return a null? #2602
-
I am converting a project from Beta4 to Beta5. I can mostly convert without issue, but now that Is there not an easier way? // Converted to B5 format
Option<string> versionOption = new("--version")
{
Description = "Version JSON file.",
DefaultValueFactory = _ => "./Make/Version.json",
};
// Converted to B5 format
Command matrixCommand = new("matrix", "Create matrix information file")
{
versionOption,
matrixOption,
updateOption,
};
matrixCommand.SetAction(parseResult =>
{
return MatrixHandler(
parseResult.GetValue(versionOption), // Possible null reference
parseResult.GetValue(matrixOption),
parseResult.GetValue(updateOption)
);
});
// B4 format
Command schemaCommand = new("schema", "Write Version and Matrix JSON schema files")
{
schemaVersionOption,
schemaMatrixOption,
};
schemaCommand.SetAction(SchemaHandler, schemaVersionOption, schemaMatrixOption); Is there a way to pass the options that will guarantee a |
Beta Was this translation helpful? Give feedback.
Replies: 2 comments 2 replies
-
Are you seeing Some details of how this works are being hashed out in #2601. |
Beta Was this translation helpful? Give feedback.
-
RootCommand command = new RootCommand("Example - Does something");
Option<string> nameOption = new Option<string>("--name")
{
Description = "Your name",
DefaultValueFactory = _ => "World"
};
command.Options.Add(nameOption);
command.SetAction(pr =>
{
string name = pr.GetRequiredValue(nameOption);
Console.WriteLine($"Hello, {name}!");
});
command.Parse(args).Invoke(); Calling the former program with If the So, to summarise:
|
Beta Was this translation helpful? Give feedback.
GetValue
returnsT?
by default, meaning for anOption<string>
it will returnstring?
(nullable).GetRequiredValue
seems to return the type itself and use theDefaultValueFactory
if it's not provided.Calling the former program with
--name ptr727
will print "Hello, ptr727!", and calling it without arguments wi…