clap/clap_complete/tests/snapshots/value_hint.ps1
Ed Page 36bc641648 fix(help): Remove extraneous text from built-ins
This is an intermediate solution for #4408.  As there were no agreeed
upon goals, I went with what I felt read well and that I saw commonly
used on non-clap commands.

- "information" isn't really a necessary word.
- I originally favored `Print this help` but realied that doesn't read
  correctly in completions.
- Besides being shorter, the reason for the flipped short/long hint is
  it gives people the context they need for scanning, emphasizing
  "summary" and "more".

Fixes #4409
2023-01-03 11:02:26 -06:00

52 lines
3.1 KiB
PowerShell

using namespace System.Management.Automation
using namespace System.Management.Automation.Language
Register-ArgumentCompleter -Native -CommandName 'my-app' -ScriptBlock {
param($wordToComplete, $commandAst, $cursorPosition)
$commandElements = $commandAst.CommandElements
$command = @(
'my-app'
for ($i = 1; $i -lt $commandElements.Count; $i++) {
$element = $commandElements[$i]
if ($element -isnot [StringConstantExpressionAst] -or
$element.StringConstantType -ne [StringConstantType]::BareWord -or
$element.Value.StartsWith('-') -or
$element.Value -eq $wordToComplete) {
break
}
$element.Value
}) -join ';'
$completions = @(switch ($command) {
'my-app' {
[CompletionResult]::new('--choice', 'choice', [CompletionResultType]::ParameterName, 'choice')
[CompletionResult]::new('--unknown', 'unknown', [CompletionResultType]::ParameterName, 'unknown')
[CompletionResult]::new('--other', 'other', [CompletionResultType]::ParameterName, 'other')
[CompletionResult]::new('-p', 'p', [CompletionResultType]::ParameterName, 'p')
[CompletionResult]::new('--path', 'path', [CompletionResultType]::ParameterName, 'path')
[CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'f')
[CompletionResult]::new('--file', 'file', [CompletionResultType]::ParameterName, 'file')
[CompletionResult]::new('-d', 'd', [CompletionResultType]::ParameterName, 'd')
[CompletionResult]::new('--dir', 'dir', [CompletionResultType]::ParameterName, 'dir')
[CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'e')
[CompletionResult]::new('--exe', 'exe', [CompletionResultType]::ParameterName, 'exe')
[CompletionResult]::new('--cmd-name', 'cmd-name', [CompletionResultType]::ParameterName, 'cmd-name')
[CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'c')
[CompletionResult]::new('--cmd', 'cmd', [CompletionResultType]::ParameterName, 'cmd')
[CompletionResult]::new('-u', 'u', [CompletionResultType]::ParameterName, 'u')
[CompletionResult]::new('--user', 'user', [CompletionResultType]::ParameterName, 'user')
[CompletionResult]::new('-H', 'H', [CompletionResultType]::ParameterName, 'H')
[CompletionResult]::new('--host', 'host', [CompletionResultType]::ParameterName, 'host')
[CompletionResult]::new('--url', 'url', [CompletionResultType]::ParameterName, 'url')
[CompletionResult]::new('--email', 'email', [CompletionResultType]::ParameterName, 'email')
[CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help')
[CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help')
break
}
})
$completions.Where{ $_.CompletionText -like "$wordToComplete*" } |
Sort-Object -Property ListItemText
}