using namespace System.Management.Automation using namespace System.Management.Automation.Language Register-ArgumentCompleter -Native -CommandName 'complate' -ScriptBlock { param($wordToComplete, $commandAst, $cursorPosition) $commandElements = $commandAst.CommandElements $command = @( 'complate' 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) { 'complate' { [CompletionResult]::new('-e', 'e', [CompletionResultType]::ParameterName, 'enables experimental features') [CompletionResult]::new('--experimental', 'experimental', [CompletionResultType]::ParameterName, 'enables experimental features') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.') [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.') [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes a dummy default configuration in "./.complate/config.yaml".') [CompletionResult]::new('schema', 'schema', [CompletionResultType]::ParameterValue, 'Renders the configuration schema.') [CompletionResult]::new('render', 'render', [CompletionResultType]::ParameterValue, 'Renders a template by replacing values as specified by the configuration.') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } 'complate;man' { [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'o') [CompletionResult]::new('--out', 'out', [CompletionResultType]::ParameterName, 'out') [CompletionResult]::new('-f', 'f', [CompletionResultType]::ParameterName, 'f') [CompletionResult]::new('--format', 'format', [CompletionResultType]::ParameterName, 'format') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break } 'complate;autocomplete' { [CompletionResult]::new('-o', 'o', [CompletionResultType]::ParameterName, 'o') [CompletionResult]::new('--out', 'out', [CompletionResultType]::ParameterName, 'out') [CompletionResult]::new('-s', 's', [CompletionResultType]::ParameterName, 's') [CompletionResult]::new('--shell', 'shell', [CompletionResultType]::ParameterName, 'shell') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break } 'complate;init' { [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break } 'complate;schema' { [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break } 'complate;render' { [CompletionResult]::new('-c', 'c', [CompletionResultType]::ParameterName, 'The configuration file to use.') [CompletionResult]::new('--config', 'config', [CompletionResultType]::ParameterName, 'The configuration file to use.') [CompletionResult]::new('-t', 't', [CompletionResultType]::ParameterName, 'Specify the template to use from the config and skip it''s selection.') [CompletionResult]::new('--template', 'template', [CompletionResultType]::ParameterName, 'Specify the template to use from the config and skip it''s selection.') [CompletionResult]::new('-b', 'b', [CompletionResultType]::ParameterName, 'The execution backend (cli=native-terminal, ui=ui emulator in terminal).') [CompletionResult]::new('--backend', 'backend', [CompletionResultType]::ParameterName, 'The execution backend (cli=native-terminal, ui=ui emulator in terminal).') [CompletionResult]::new('-v', 'v', [CompletionResultType]::ParameterName, 'Overrides a certain value definition with a string.') [CompletionResult]::new('--value', 'value', [CompletionResultType]::ParameterName, 'Overrides a certain value definition with a string.') [CompletionResult]::new('--trust', 'trust', [CompletionResultType]::ParameterName, 'Enables the shell command execution. This is potentially insecure and should only be done for trustworthy sources.') [CompletionResult]::new('-l', 'l', [CompletionResultType]::ParameterName, 'Defines that the templating is done in non-strict mode (allow missing value for variable).') [CompletionResult]::new('--loose', 'loose', [CompletionResultType]::ParameterName, 'Defines that the templating is done in non-strict mode (allow missing value for variable).') [CompletionResult]::new('-h', 'h', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('--help', 'help', [CompletionResultType]::ParameterName, 'Print help') [CompletionResult]::new('-V', 'V ', [CompletionResultType]::ParameterName, 'Print version') [CompletionResult]::new('--version', 'version', [CompletionResultType]::ParameterName, 'Print version') break } 'complate;help' { [CompletionResult]::new('man', 'man', [CompletionResultType]::ParameterValue, 'Renders the manual.') [CompletionResult]::new('autocomplete', 'autocomplete', [CompletionResultType]::ParameterValue, 'Renders shell completion scripts.') [CompletionResult]::new('init', 'init', [CompletionResultType]::ParameterValue, 'Initializes a dummy default configuration in "./.complate/config.yaml".') [CompletionResult]::new('schema', 'schema', [CompletionResultType]::ParameterValue, 'Renders the configuration schema.') [CompletionResult]::new('render', 'render', [CompletionResultType]::ParameterValue, 'Renders a template by replacing values as specified by the configuration.') [CompletionResult]::new('help', 'help', [CompletionResultType]::ParameterValue, 'Print this message or the help of the given subcommand(s)') break } 'complate;help;man' { break } 'complate;help;autocomplete' { break } 'complate;help;init' { break } 'complate;help;schema' { break } 'complate;help;render' { break } 'complate;help;help' { break } }) $completions.Where{ $_.CompletionText -like "$wordToComplete*" } | Sort-Object -Property ListItemText }