patriksvensson / dotnet-example

A dotnet tool to list and run examples
MIT License
170 stars 15 forks source link

Non-csproj based examples #8

Open tig opened 2 years ago

tig commented 2 years ago

My project (https://github.com/migueldeicaza/gui.cs) has an example app called UI Catalog. The main UI Catalog app uses reflection to enumerate and display all of the examples; they all derive from the class Scenario:

image image

The Scenarios are all in the ./Scenarios dir; each as an individual .cs file. The filename (e.g. Generic.cs DOES NOT need to match the name of the Scenario (the real name is metadata on the Sceanario class).

UI Catalog accepts the name of a Scenario on the command line; if provided it will directly launch that Scenario.

I'd like to enable dotnet example <Scenario>.

I do not want to force each Scenario to have a .csproj file or to be in a distinct dir.

I do not want to have to modify the existing Scenarios.

I do not want to have Scenario writers have to modify anything but their .cs file (e.g. adding each Scenario to .examples is no bueno).

I'm happy to contribute to this project to enhance it to support what I'm trying to do.

What would be your suggestion on the best way to do this?

My initial thought was to enhance .examples such that this will work:

# Sample .examples file for UICatalog Scenarios
./UICatalog --list

dotnet example --list would then build UICatalog/UICatalog.csproj and run it with --list. It would capture stdout to capture the resulting list of examples ("Name", "Description" pairs).

dotnet example <Scenario> would build UICatalog/UICatalog.csproj and run it with <Scenario>.

What do you think?