-
Notifications
You must be signed in to change notification settings - Fork 106
Expand file tree
/
Copy pathArgumentCompleter.cs
More file actions
97 lines (87 loc) · 3.1 KB
/
ArgumentCompleter.cs
File metadata and controls
97 lines (87 loc) · 3.1 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
// Copyright (c) Microsoft Corporation. All rights reserved.
// Licensed under the MIT License.
using Microsoft.PowerShell.PSResourceGet.UtilClasses;
using System.Collections;
using System.Collections.Generic;
using System.Management.Automation;
using System.Management.Automation.Language;
internal class RuntimeIdentifierCompleter : IArgumentCompleter
{
private static readonly string[] s_knownRids = new[]
{
"win-x64", "win-x86", "win-arm64",
"linux-x64", "linux-arm64", "linux-arm", "linux-musl-x64", "linux-musl-arm64",
"osx-x64", "osx-arm64",
};
public IEnumerable<CompletionResult> CompleteArgument(
string commandName,
string parameterName,
string wordToComplete,
CommandAst commandAst,
IDictionary fakeBoundParameters)
{
wordToComplete = Utils.TrimQuotes(wordToComplete);
var wordToCompletePattern = WildcardPattern.Get(
pattern: string.IsNullOrWhiteSpace(wordToComplete) ? "*" : wordToComplete + "*",
options: WildcardOptions.IgnoreCase);
foreach (string rid in s_knownRids)
{
if (wordToCompletePattern.IsMatch(rid))
{
yield return new CompletionResult(rid);
}
}
}
}
internal class TargetFrameworkCompleter : IArgumentCompleter
{
private static readonly string[] s_knownTfms = new[]
{
"net472", "net48",
"netstandard2.0", "netstandard2.1",
"net6.0", "net7.0", "net8.0", "net9.0",
};
public IEnumerable<CompletionResult> CompleteArgument(
string commandName,
string parameterName,
string wordToComplete,
CommandAst commandAst,
IDictionary fakeBoundParameters)
{
wordToComplete = Utils.TrimQuotes(wordToComplete);
var wordToCompletePattern = WildcardPattern.Get(
pattern: string.IsNullOrWhiteSpace(wordToComplete) ? "*" : wordToComplete + "*",
options: WildcardOptions.IgnoreCase);
foreach (string tfm in s_knownTfms)
{
if (wordToCompletePattern.IsMatch(tfm))
{
yield return new CompletionResult(tfm);
}
}
}
}
internal class RepositoryNameCompleter : IArgumentCompleter
{
public IEnumerable<CompletionResult> CompleteArgument(
string commandName,
string parameterName,
string wordToComplete,
CommandAst commandAst,
IDictionary fakeBoundParameters)
{
List<PSRepositoryInfo> listOfRepositories = RepositorySettings.Read(null, out string[] _);
wordToComplete = Utils.TrimQuotes(wordToComplete);
var wordToCompletePattern = WildcardPattern.Get(
pattern: string.IsNullOrWhiteSpace(wordToComplete) ? "*" : wordToComplete + "*",
options: WildcardOptions.IgnoreCase);
foreach (PSRepositoryInfo repo in listOfRepositories)
{
string repoName = repo.Name;
if (wordToCompletePattern.IsMatch(repoName))
{
yield return new CompletionResult(Utils.QuoteName(repoName));
}
}
}
}