Skip to content

Document the way to add a completion source to a command #58

@dotnetKyle

Description

@dotnetKyle

Add documentation for this pattern:

// Command

public class MyData
{
    [Handler("my-command")]
    public void Execute(string csvFilePath)
    {
        if (File.Exists(csvFilePath))
        {
            ...
        }
    }

    public static IEnumerable<CompletionItem> GetFileNameCompletions(CompletionContext ctx)
    {
        string fn = ctx.WordToComplete;
        string[] files = Directory.GetFiles(Environment.CurrentDirectory, fn + "*.csv");
        return files.Select(f => new CompletionItem(f));
    }
}
// setup
builder.MapMyDataCommand(options =>
{
    options.Command.Description = "Load something from a CSV file.";
    options.CsvFilePathArgument.Description = "The file path to the CSV file where the data is stored.";
    // map the command completions like this:
    options.CsvFilePathArgument.CompletionSources.Add(MyData.GetFileNameCompletions);
});

Metadata

Metadata

Assignees

No one assigned

    Labels

    documentationImprovements or additions to documentation

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions