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

WIP Tab completion for CLI #727

Closed
wants to merge 12 commits into from

Conversation

Jawz84
Copy link

@Jawz84 Jawz84 commented Feb 6, 2022

The goal of this pull request is to add out-of-the-box completer functionality to Spectre.Console, as suggested in #267.

The approach will be to mimic what a tool like dotnet complete does. As a result, the completion scripts that people can use, will be analogous to those for dotnet complete.

@CLAassistant
Copy link

CLAassistant commented Feb 6, 2022

CLA assistant check
All committers have signed the CLA.

@Jawz84
Copy link
Author

Jawz84 commented Feb 6, 2022

@patriksvensson @phil-scott-78 Do you feel am I taking this in the right direction? Today's start, to me, felt promising. Let me know your thoughts, and feel free to add (failing) tests to provide more specific direction.
The current four tests pass.

@Jawz84
Copy link
Author

Jawz84 commented Feb 7, 2022

I forgot to catch the actual parser error, so... I was accidentally muting an index out of bounds exception.. fixed now.

@phil-scott-78
Copy link
Contributor

I'm going to pul this down tonight and play with it. So far it looks really cool.

One scenario that I was thinking about was being able to add a service to commands to specify valid values when they are resolved. E.g. when I type git add a<TAB> the add verb is clever enough to suggest dirty files starting with the letter a.

@Jawz84
Copy link
Author

Jawz84 commented Feb 12, 2022

@phil-scott-78 I'm not entirely sure yet how to add what you mentioned above. Could you provide a pseudo code draft?

I added option parameter support and some more tests.

* Adding a dark mode
* Adding reference for types to summary pages
* Adding API Reference
* Adding modifiers to methods/fields/etc
* Minimizing files input
* Caching a lot of the output pages
* Cache only for each execution
* Adding API references to existing docs
@phil-scott-78
Copy link
Contributor

So my thought was given this settings

public class FooCommandSettings : CommandSettings
{
    [CommandArgument(0, "[QUX]")]
    [Description("The qux value.")]
    public string Qux { get; set; }
}

Let's assume Qux might be a list of *.qux files in the current folder or sub-folder.

Someone types in myapp.exe p<TAB> the app would be able to autocompletion info in the form of all the files that are p*.qux.

To implement perhaps would work like the `ParameterValidationAttribute

public sealed class FileCompletionAttribute : ParameterValidationAttribute
{
    public override string[] Complete(CommandParameterContext context, string partialElement)
    {
        return GetQuxCompletions(partialElement);
    }
}



public class FooCommandSettings : CommandSettings
{
    [CommandArgument(0, "[QUX]")]
    [Description("The qux value.")]
    [FileCompletionAttribute]
    public string Qux { get; set; }
}

@Jawz84
Copy link
Author

Jawz84 commented Feb 15, 2022

It's absolutely the next step and would be super cool to have. I'll have a look at where this would fit, thanks for the input, appreciate it!

@FrankRay78
Copy link
Contributor

Hello @Jawz84, I'm just checking in to see if you made any further progress with this PR?

@FrankRay78 FrankRay78 added the area-CLI Command-Line Interface label May 13, 2023
@FrankRay78 FrankRay78 changed the title WIP Fixes #267 completer WIP Tab completion for CLI May 13, 2023
@Jawz84
Copy link
Author

Jawz84 commented May 14, 2023 via email

@FrankRay78
Copy link
Contributor

Thanks for replying @Jawz84 , it's no disappointment and all contributions, even unmerged WIP PRs are appreciated. I was just doing some housekeeping across the open issues and PRs to check on any progress.

Regarding tab completion, and whilst I don't know anything about MacOS and Linux, it seems more involved than it first appears: https://learn.microsoft.com/en-us/dotnet/core/tools/enable-tab-autocomplete ie. each shell seems to need custom configuration manually added before tab completion actually works

Anyhow, I'm going to close this PR given your comment above and you can always come back to it later if you so desire. Or not. Take care

@FrankRay78 FrankRay78 closed this May 15, 2023
@Jawz84
Copy link
Author

Jawz84 commented May 15, 2023 via email

@JKamsker JKamsker mentioned this pull request Jul 19, 2023
4 tasks
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area-CLI Command-Line Interface
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants