Skip to content

Commit 36a7fd9

Browse files
committed
Added experimental completer
1 parent 8065935 commit 36a7fd9

File tree

2 files changed

+36
-3
lines changed

2 files changed

+36
-3
lines changed
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
using System;
2+
using System.Collections;
3+
using System.Collections.Generic;
4+
using System.Linq;
5+
using System.Management.Automation;
6+
using System.Management.Automation.Language;
7+
using Microsoft.SharePoint.Client;
8+
9+
namespace PnP.PowerShell.Commands.Base.Completers
10+
{
11+
public sealed class ListNameCompleter : IArgumentCompleter
12+
{
13+
public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
14+
{
15+
IEnumerable<List> result = PnPConnection.Current.Context.LoadQuery(PnPConnection.Current.Context.Web.Lists.Include(list => list.Title));
16+
PnPConnection.Current.Context.ExecuteQueryRetry();
17+
foreach (var list in result.Where(l => l.Title.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)))
18+
{
19+
yield return new CompletionResult(list.Title);
20+
}
21+
22+
}
23+
}
24+
}

src/Commands/Lists/GetList.cs

Lines changed: 12 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,14 @@
55
using System;
66
using Resources = PnP.PowerShell.Commands.Properties.Resources;
77
using PnP.PowerShell.Commands.Attributes;
8+
using System.Collections.Generic;
9+
using System.Management.Automation.Language;
10+
using System.Collections;
11+
using PnP.Core.Services;
12+
using PnP.PowerShell.Commands.Base;
13+
using System.Linq;
14+
using AngleSharp.Dom;
15+
using PnP.PowerShell.Commands.Base.Completers;
816

917
namespace PnP.PowerShell.Commands.Lists
1018
{
@@ -21,15 +29,15 @@ namespace PnP.PowerShell.Commands.Lists
2129
[RequiredApiDelegatedPermissions("sharepoint/AllSites.FullControl")]
2230
public class GetList : PnPWebRetrievalsCmdlet<List>
2331
{
24-
[Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0)]
25-
public ListPipeBind Identity;
32+
[Parameter(Mandatory = false, ValueFromPipeline = true, Position = 0), ArgumentCompleter(typeof(ListNameCompleter))]
33+
public ListPipeBind Identity { get; set; }
2634

2735
[Parameter(Mandatory = false)]
2836
public SwitchParameter ThrowExceptionIfListNotFound;
2937

3038
protected override void ExecuteCmdlet()
3139
{
32-
DefaultRetrievalExpressions = new Expression<Func<List, object>>[] { l => l.Id, l => l.BaseTemplate, l => l.OnQuickLaunch, l => l.DefaultViewUrl, l => l.Title, l => l.Hidden, l => l.RootFolder.ServerRelativeUrl };
40+
DefaultRetrievalExpressions = [l => l.Id, l => l.BaseTemplate, l => l.OnQuickLaunch, l => l.DefaultViewUrl, l => l.Title, l => l.Hidden, l => l.RootFolder.ServerRelativeUrl];
3341

3442
if (Identity != null)
3543
{
@@ -52,3 +60,4 @@ protected override void ExecuteCmdlet()
5260
}
5361
}
5462
}
63+

0 commit comments

Comments
 (0)