Skip to content
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

Support metadata based CLI: was Demo/test case: TaskRunner parsing #461

Open
jzabroski opened this issue Mar 15, 2019 · 4 comments
Open

Comments

@jzabroski
Copy link

jzabroski commented Mar 15, 2019

Imagine an exe called TaskRunner.dll that has a bunch of TaskDefinition<T> sub-classes.

I would like to provide dotnet-suggest support for each one. To do this, I would need to load, using reflection, an instance of each TaskDefinition and be able to explain to System.CommandLine how to use this metadata to provide command line auto-completion suggestions.

public interface ITaskDefinition { string Key { get; } }
public abstract class TaskDefinitionBase<T> : ITaskDefinition where T : ITask
{
  public abstract string Key { get; }
}
public class CleanFullTaskDefinition<T> : TaskDefinition<CleanFullTask>
{
  public override string Key => "cleanfull";
}
public class SqlExecuteTaskDefinition<T> : TaskDefinition<SqlExecuteTask>
{
  public override string Key => "sqlcmd";
}
public class FluentMigratorTaskDefinition<T> : TaskDefinition<FluentMigratorTask>
{
  public override string Key => "fm";
}
// etc, 1,000s of tasks to build Gilles Tréhin's Urville :)
@jonsequitur
Copy link
Contributor

This should be pretty straightforward. Argument.AddSuggestionSource can be used to provide dynamic suggestions via a delegate or via your own implementation of ISuggestionSource.

Depending on how many tasks there are and whether the scan will be costly, you might consider doing this reflection only once and caching it, e.g. creating this index at build time or writing a file to disk after the first scan.

@jzabroski
Copy link
Author

jzabroski commented Mar 16, 2019 via email

@jonsequitur
Copy link
Contributor

I would be happy to look at the code and help work through the use case. This sounds like it falls under the general category of app models that sit on top of the core functionality and we want to enable scenarios like this but building the app models themselves isn't the general goal of this project so a separate repo would be best.

@jzabroski
Copy link
Author

jzabroski commented Mar 18, 2019

Thank you, Jon! I somewhat agree, but the problem with splitting these things out into separate repos is you lose the benefits of ReSharper refactoring things and so the downstream maintainers get stuck with double (or more) of the work. I also think a "plugin of plugin" model is a fairly realistic scenario, in that every job I've ever worked on has needed some command-line tool to orchestrate tasks. It would just be unique in the sense that it's turtles all the way down: You plug in your TaskRunner plugin into dotnet.exe tools, and you plug-in Task plug-ins into TaskRunner. (MSBuild just happens to be a special case where the Tasks are build related rather than problem domain related.)

In effect, what this demo is really demonstrating is how to build a W-grammar/attribute grammar using System.CommandLine: each Task implements its own context-free grammar via the Argument.AddSuggestionSource (if I understand it correctly - I'll try to prototype this weekend.)

@KathleenDollard KathleenDollard changed the title Demo/test case: TaskRunner parsing Support metadata based CLI: was Demo/test case: TaskRunner parsing Dec 11, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants