Created
January 9, 2022 16:25
-
-
Save santisq/6109cb1ec65e02cbe3810c70d1b155b1 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| using namespace System.Management.Automation | |
| using namespace System.Management.Automation.Language | |
| using namespace System.Collections | |
| using namespace System.Collections.Generic | |
| class Completer : IArgumentCompleter { | |
| [IEnumerable[CompletionResult]] CompleteArgument( | |
| [string]$CommandName, | |
| [string]$ParameterName, | |
| [string]$WordToComplete, | |
| [CommandAst]$CommandAst, | |
| [IDictionary]$FakeBoundParameters | |
| ) { | |
| $result = [List[CompletionResult]]::new() | |
| DateTimeSpan | Where-Object { $_ -like "*$wordToComplete*" } | ForEach-Object { | |
| $result.Add( | |
| [CompletionResult]::new( | |
| "'$_'", $_, [CompletionResultType]::ParameterValue, $_ | |
| ) | |
| ) | |
| } | |
| return $result | |
| } | |
| } | |
| function DateTimeSpan { | |
| param( | |
| [datetime]$Date | |
| ) | |
| $start = [datetime]::now | |
| $end = [datetime]::now.AddDays(1) | |
| $timespan = for($i = $start; $i -lt $end; $i = $i.AddHours(1)) | |
| { | |
| $i.ToString() | |
| } | |
| $timespan | |
| } | |
| function Test-ArgumentCompleter { | |
| param( | |
| [ArgumentCompleter([Completer])] | |
| $Test | |
| ) | |
| $Test | |
| } | |
| Test-ArgumentCompleter |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment