sdk icon indicating copy to clipboard operation
sdk copied to clipboard

Support Json format for `dotnet new list`

Open MoaidHathot opened this issue 2 years ago • 8 comments

Is your feature request related to a problem? Please describe.

Calling dotnet new list generates a table-based output. Due to terminal size constraints some values may be automatically truncated, making it very hard for other tools to use the .NET CLI (like a Neovim extension).

Describe the solution you'd like

Support --format json as it already supported in other commands.

Additional context

image

MoaidHathot avatar Sep 25 '24 09:09 MoaidHathot

This is definitely a good thing to do, and very in line with our more recently-created commands. We will likely take a converted stab at making sure there is machine readable output for all of our commands for the next release or two, but if this is especially important to you we'd love to take a PR adding the flag to 'dotnet new list'.

baronfel avatar Sep 25 '24 12:09 baronfel

@MoaidHathot Do you plan on making a PR for this? No pressure of course.. I want to make sure if you did any work already, we don't discount any contribution you might be working on. We are considering picking this task up

nagilson avatar Oct 01 '24 22:10 nagilson

Hi @nagilson, yes, I'm working on a PR. Planning to publish it or a draft of it in the following couple of days.

MoaidHathot avatar Oct 02 '24 08:10 MoaidHathot

@MoaidHathot please confirm that you're working on the task - I've recently finished cooperation with my employer and I would use some C# tasks to do in my spare time (which I have lot of) moreover - this task looks quite nice for the first task todo on an OSS and start to be a OSS collaborator so I would like to put my hands on it but don't want to interfere with your work if you had done some of it

mariuszbyahoo avatar Oct 13 '24 09:10 mariuszbyahoo

Hi @baronfel, @nagilson, @mariuszbyahoo, I've created the following draft PR https://github.com/dotnet/sdk/pull/44140/files and I'm seeking a discussion and a quick review. I created the draft so that it is easier to discuss the design before making more complete changes, this is just a draft to explain my intent. The thing I'm not sure about is whether we should reuse TemplateGroupDisplay and TemplateGroupTableRow as I've done, although they are part of the TabularOutput namespace. We can move them from the TabularOutput namespace of course.

The following is the output I'm currently getting, as a PoC, we will probably change it a bit so that the output is not an array, but a json object containing a property of type array:

[
  {
    "Author": "Microsoft",
    "Classifications": "Common/WinForms",
    "Languages": "[C#],VB",
    "Name": "Windows Forms Control Library",
    "ShortNames": "winformscontrollib",
    "Type": "project"
  },
  {
    "Author": "Microsoft",
    "Classifications": "Common/WinForms",
    "Languages": "[C#],VB",
    "Name": "Windows Forms Class Library",
    "ShortNames": "winformslib",
    "Type": "project"
  },
  {
    "Author": "Microsoft",
    "Classifications": "Common/WPF",
    "Languages": "[C#],VB",
    "Name": "WPF Application",
    "ShortNames": "wpf",
    "Type": "project"
  },
  {
    "Author": "Microsoft",
    "Classifications": "Common/WPF",
    "Languages": "[C#],VB",
    "Name": "WPF Class Library",
    "ShortNames": "wpflib",
    "Type": "project"
  },
  {
    "Author": "Microsoft",
    "Classifications": "Common/WPF",
    "Languages": "[C#],VB",
    "Name": "WPF Custom Control Library",
    "ShortNames": "wpfcustomcontrollib",
    "Type": "project"
  },
  {
    "Author": "Microsoft",
    "Classifications": "Common/WPF",
    "Languages": "[C#],VB",
    "Name": "WPF User Control Library",
    "ShortNames": "wpfusercontrollib",
    "Type": "project"
  }
]

MoaidHathot avatar Oct 13 '24 17:10 MoaidHathot

@MoaidHathot thanks for putting out the draft! A few notes on the format from my end:

  • When you say "we will probably change it a bit so that the output is not an array, but a json object containing a property of type array", what's driving that thought?
  • There are a few aspects of the current TemplateGroupTableRow that I would want to change in a purely-JSON representation:
    • Classifications should be an array of the string tags, not /-delimited
    • Languages should be an array of { id: string, default: bool } objects to capture the semantics of the list of languages and which one is currently the one that will be chosen absent any user override
    • ShortNames should be an array of the names, not ,-separated

Basically, the json should be as idiomatic JSON as possible. I'd love for this to be an actual class/structure in the codebase that we can serialize an array of (or something) so that we have an actual contract that we have to think about evolving if we want to change it.

baronfel avatar Oct 13 '24 19:10 baronfel

@baronfel, thank you for the quick review.

Basically, the json should be as idiomatic JSON as possible. I'd love for this to be an actual class/structure in the codebase that we can serialize an array of (or something) so that we have an actual contract that we have to think about evolving if we want to change it.

Totally agree, I'll make the change

When you say "we will probably change it a bit so that the output is not an array, but a json object containing a property of type array", what's driving that thought?

Since it seems to be the standard in other --format json results, although all or most of them are ForwardedApp Commands to the Nuget CLI.

For example, the following is the output of dotnet list .\src\Dumpify\Dumpify.csproj package --format json. It contain a schema version which I think is important.

{
  "version": 1,
  "parameters": "",
  "problems": [
    {
      "level": "warning",
      "text": "(A) : Auto-referenced package."
    }
  ],
  "projects": [
    {
      "path": "P:/Github/Dumpify/src/Dumpify/Dumpify.csproj",
      "frameworks": [
        {
          "framework": "netstandard2.0",
          "topLevelPackages": [
            {
              "id": "NETStandard.Library",
              "requestedVersion": "[2.0.3, )",
              "resolvedVersion": "2.0.3",
              "autoReferenced": "true"
            },
            {
              "id": "Spectre.Console",
              "requestedVersion": "0.48.0",
              "resolvedVersion": "0.48.0"
            }
          ]
        },
        {
          "framework": "netstandard2.1",
          "topLevelPackages": [
            {
              "id": "Spectre.Console",
              "requestedVersion": "0.48.0",
              "resolvedVersion": "0.48.0"
            }
          ]
        },
        {
          "framework": "net8.0",
          "topLevelPackages": [
            {
              "id": "Spectre.Console",
              "requestedVersion": "0.48.0",
              "resolvedVersion": "0.48.0"
            }
          ]
        }
      ]
    }
  ]
}

MoaidHathot avatar Oct 13 '24 19:10 MoaidHathot

Ok, that's what I expected - you're thinking about protocol extensibility, compatibility and such. That makes perfect sense, just wanted to make sure what I interpreted your meaning as was what you meant your meaning to be interpreted as :)

baronfel avatar Oct 13 '24 20:10 baronfel