Repository navigation
Enable command line completion with complete command - #521
Conversation
…g candidate words
|
|
||
| WinGet offers a `complete` command that can be leveraged by your shell to provide context sensitive tab completion. It allows for completion of command names, argument names, and argument values, dependent on the current command line state. | ||
|
|
||
| > Note, this feature has not yet been released. Hold tight, it is coming soon! |
There was a problem hiding this comment.
Are you going to be able to remember this line when it's released?
There was a problem hiding this comment.
That's the plan, but if not I'm sure someone will poke us.
| { | ||
| using namespace std::string_view_literals; | ||
|
|
||
| using namespace Execution; |
There was a problem hiding this comment.
nit #Pending
| // be context sensitive in their data output. | ||
| struct CompleteCommand final : public Command | ||
| { | ||
| CompleteCommand(std::string_view parent) : Command("complete", parent, Visibility::Hidden) {} |
There was a problem hiding this comment.
CompleteCommand(std::string_view parent) : Command("complete", parent, Visibility::Hidden) {} [](start = 8, length = 93)
So we are not going to release it as an experimental feature? #ByDesign
There was a problem hiding this comment.
No, since you have to opt in by setting up your shell to call into this, and it is otherwise out of the way, it isn't really necessary.
In reply to: 463771454 [](ancestors = 463771454)
| } | ||
|
|
||
| // Reporter should be the central place to show workflow status to user. | ||
| // Todo: need to implement actual console output to show progress bar, etc |
There was a problem hiding this comment.
// Todo: need to implement actual console output to show progress bar, etc [](start = 4, length = 74)
nit: this could be removed #Pending
| int32_t i = 0; | ||
|
|
||
| while (i != UBRK_DONE) | ||
| // Count past end, convert to npos to get all of string |
There was a problem hiding this comment.
Count past end [](start = 11, length = 14)
curious why do we not treat this as a bad input? #ByDesign
There was a problem hiding this comment.
|
Maybe look at making it work with edit: It is compatible while being installed along side with the above, but the above alone isn't sufficient to cause it to auto-complete win-get |
This year as part of Microsoft's Hackathon, I decided I wanted to explore how to implement a
completecommand following the pattern of thedotnetCLI's complete command, as referenced in #331 and #146.Change
The goal of the change was to add the complete command, but it ended up having many side effects and becoming quite large. It may have also fixed a few bugs along the way. After I cover the complete command portion, I will detail the other side effects and bug fixes changes.
The MD file that I added to describe tab completion and the command can be seen here. The basic premise is that we take in the current command line, cursor position, and "word" to be completed.
From this we construct a
CompletionDataobject, which breaks the arguments into our standard command line processing structures. These are segregated into before and after the word to complete. We then create a newContextobject, attach theCompletionDataand use the same parsing methods as standard inputs to determine which command is being targeted. Finally, we pass theContextto the newCommand::Completemethod.The
Completemethod breaks down the remainingCompletionDatato generate three different potential sets of options:If an argument value is a potential option, a virtual function on the command is called to allow it to provide context sensitive results. It receives the
Contextcreated originally, which has had it'sArgsfilled out during processing. Using thisContext, existingWorkflowfunctionality and paradigms can be leveraged to construct potential completions.Examples
winget ⇥winget installinstallis the first command below the rootwinget sh⇥winget showshowis the first command that starts withshwinget source l⇥winget source listlistis the first sub-command of source that starts withlwinget -⇥winget --version--versionis the first argument defined for the rootwinget install power⇥winget install "Power Toys""Power Toys"is the first package whose Id, Name, or Moniker starts withpowerwinget install "Power Toys" --version ⇥winget install "Power Toys" --version 0.19.20.19.2is the highest version of Power Toys at the time of writingOther Changes
In addition to the
completecommand, these other changes are included:OutputStreamout ofReporter, which should result in more consistent--no-vtbehavior.Reporter, which enables us to select which type of output is allowed.Reporterto make it more of an instance; this meant makingConsoleModeRestorea singleton as it should have been.UTF8Substringwhen count causes the substring to extend past the end of the input.Command::Completeto prevent any errors in common code from showing up as noise.StartsWithmatch type to the search interface.Validation
Tests are added for
CompletionDataandCommand::Completehandling of said data. Tests are also added forStartsWithsearches and string comparisons.Microsoft Reviewers: Open in CodeFlow