-
Notifications
You must be signed in to change notification settings - Fork 1.1k
dotnet CLI: Add --cli-schema option for CLI structure JSON #49118
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
base: main
Are you sure you want to change the base?
Conversation
…utput the structure of that command in JSON. This still has work to be done to refine the output.
src/Cli/dotnet/CommandLineInfo.cs
Outdated
writer.WriteStartObject(nameof(command.Arguments).ToCamelCase()); | ||
foreach (var argument in command.Arguments.OrderBy(a => a.Name)) | ||
{ | ||
// TODO: Check these | ||
writer.WriteStartObject(argument.Name); | ||
|
||
writer.WriteString(nameof(argument.Description).ToCamelCase(), argument.Description); | ||
writer.WriteBoolean(nameof(argument.Hidden).ToCamelCase(), argument.Hidden); | ||
writer.WriteBoolean("hasValidators", argument.GetHasValidators() ?? false); | ||
writer.WriteString(nameof(argument.HelpName).ToCamelCase(), argument.HelpName); | ||
writer.WriteString(nameof(argument.ValueType).ToCamelCase(), argument.ValueType.FullName); | ||
writer.WriteBoolean(nameof(argument.HasDefaultValue).ToCamelCase(), argument.HasDefaultValue); | ||
|
||
writer.WriteStartObject(nameof(argument.Arity).ToCamelCase()); | ||
writer.WriteNumber(nameof(argument.Arity.MinimumNumberOfValues).ToCamelCase(), argument.Arity.MinimumNumberOfValues); | ||
writer.WriteNumber(nameof(argument.Arity.MaximumNumberOfValues).ToCamelCase(), argument.Arity.MaximumNumberOfValues); | ||
writer.WriteEndObject(); | ||
|
||
writer.WriteEndObject(); | ||
} | ||
writer.WriteEndObject(); |
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.
TODO: Local functions might make sense for each of these sub-sections.
#pragma warning disable IDE0065 // Misplaced using directive | ||
using Command = System.CommandLine.Command; | ||
#pragma warning restore IDE0065 // Misplaced using directive |
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.
This is bizarre but necessary since declaring the using
above the namespace means that anything in the namespace scope will override it. Meaning, System.DotNet.Cli.Utils.Command
will be used even if an alias is declared. So, you put the alias inside the namespace to have it be used properly.
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.
TODO: We should just change that Command
class to not be called Command
since CliCommand
from S.CL was changed back to Command
, which causes situations like this to happen.
src/Cli/dotnet/Program.cs
Outdated
if (parseResult.GetValue(Parser.CliSchemaOption)) | ||
{ | ||
CommandLineInfo.PrintCliSchema(parseResult.CommandResult.Command); | ||
return 0; | ||
} |
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.
This is now the highest priority option since every other option is irrelevant if this one is present.
…ded name for root command. Cleaned up type output. Added default value output. Removed ordering for arguments. Added relaxed JSON encoding.
… in-person discussion. Added version to the root. Shared json serialization options. Created strings for the --cli-schema description.
Resolves: #46345
Summary
TODO