-
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
Conversation
…utput the structure of that command in JSON. This still has work to be done to refine the output.
src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/CommandExtensions.cs
Outdated
Show resolved
Hide resolved
…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.
src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/ArgumentExtensions.cs
Outdated
Show resolved
Hide resolved
src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/OptionExtensions.cs
Outdated
Show resolved
Hide resolved
src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/StringExtensions.cs
Outdated
Show resolved
Hide resolved
src/Cli/Microsoft.DotNet.Cli.Utils/Extensions/TypeExtensions.cs
Outdated
Show resolved
Hide resolved
# Conflicts: # src/Cli/dotnet/CliStrings.resx
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.
Made a few relatively small changes based on the feedback - once tests are green this is good to go!
…can easily emit a schema later on. stylistic changes: * don't emit null values * don't emit empty nesting objects/maps * add an order property to arguments
Went kind of ham and switched to using record structures to 'capture' the json output so we can easily emit a schema later on. We talked about this when I was in Redmond @MiYanni if you remember? stylistic changes:
|
…e endings, not just the line endings emitted by the json-serialization newlines.
Alright - the only failing test left is the Docker rate limiting one. Lets merge and get this in p6! |
|
Resolves: #46345
Summary
This PR is to add the
--cli-schema
option to every command. This option will defer the operation of the command entirely, similar to--help
. When--cli-schema
is provided, the JSON representation of that command is returned. Currently, I'm keeping the--cli-schema
option as hidden as the internal structure of the CLI has many 'thorny edges' to it, and would need some massaging prior to making this option public. Plus, the actual JSON schema might want some adjustment based on feedback. So, consider the--cli-schema
option to be a preview option.Details
Running
dotnet --cli-schema
will output the entire structure of the CLI. Adding--cli-schema
to any command (such asdotnet workload install --cli-schema
) will output only the structural information about that command (in this case,dotnet workload install
).Let's look at a simple example for
dotnet clean
.Example
When running
dotnet clean --cli-schema
, you will get this output:The root JSON object contains information about
clean
. The main groups of information are the"arguments"
,"options"
, and"subcommands"
. Arguments are the non-named parameters to the command (meaning, when running the command, you only provide a value, and not a key-value pair). Options are the named parameters to the command (these are key-value pairs, such as--path "example\path\here"
). Subcommands are those commands that this command contains (if applicable).clean
contains no subcommands. If it did, these entries would be included with the same information as the root command, except without the additional root information, such as"name"
and"version"
("name"
is not required for subcommands as the key to each subcommand is the command name).For more specifics about what each part of information contains, please see the System.CommandLine repository.
Additional Notes
"valueType"
information to be different from native CLR type strings, as to use a cleaner, human-readable format."arity"
information to not be rote S.CL information sincemaximum
is an arbitrary value. Instead, if something is "OrMore", it'll have anull
value formaximum
instead."defaultValue"
can output properly into JSON based on the value type of the argument/option.dotnet workload install --cli-schema
will contain a property in the telemetry namedcommand
with the valuedotnet workload install
for this specific telemetry event name (which isdotnet/cli/schema
).