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

runtime command and settings model for Spectre.Console.CLI #1712

Open
jmderuty opened this issue Dec 9, 2024 · 0 comments
Open

runtime command and settings model for Spectre.Console.CLI #1712

jmderuty opened this issue Dec 9, 2024 · 0 comments

Comments

@jmderuty
Copy link

jmderuty commented Dec 9, 2024

Is your feature request related to a problem? Please describe.
I'm building a modular application which commands are defined by plugins. The problem is that, for security and isolation reasons these plugins are loaded in child processes, not in the same process as the CLI. I'm currently investigating using Spectre Console to parse commands and display results, while the actual processing is done in the child processes. However, it seems that commands and settings can only be added through inheritance and attributes, which in this specific case won't be an option.

Describe the solution you'd like
Additionnaly to the attribute based command declaration API, I would like to be able to declare settings and commands procedurally without creating custom classes. This rises the question of how settings would be provied to commands in this situation, maybe some kind of API related to Dictionary<string,CommandSetting> ?

var app = new CommandApp();
app.Configure(config=>
{
    config.AddCommand("foo",cmd=>
    {
        cmd.AddSetting<bool>("active",setting=>setting.DefaultValue(true).CommandOption("-a|--active"));
        cmd.OnExecute((context,settings)=>
        {
            settings.Get<bool>("active")
        });
    });
}

Describe alternatives you've considered
Another option would be for Spectre.CLI to be able to both output and consume a model of the list of commands and settings. This model could be serialized and transfered between process boundaries. However in this case, it wouldn't be possible to provide OnExecute methods for commands, and dealing with invocations accross process might add too much complexity to the library for the limited use case. It would probably involve being able to run the parsing frontend without the execution backend of AppCommand, wich is probably quite a complex endeavour.


Note: I would be interested in working on such a feature myself, but I would like input on how feasable it would be.

Please upvote 👍 this issue if you are interested in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
Status: Todo 🕑
Development

No branches or pull requests

1 participant