Skip to content

Commit 8df0658

Browse files
committed
Make auto wrapping in quotes depending on starting quote
1 parent 09c0057 commit 8df0658

File tree

6 files changed

+23
-13
lines changed

6 files changed

+23
-13
lines changed

src/Commands/Base/Completers/ContentTypeCompleter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace PnP.PowerShell.Commands.Base.Completers
1111
{
1212
public sealed class ContentTypeCompleter : PnPArgumentCompleter
1313
{
14-
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
14+
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar)
1515
{
1616
IEnumerable<ContentType> result = PnPConnection.Current.Context.LoadQuery(PnPConnection.Current.Context.Web.AvailableContentTypes.Include(f => f.Name));
1717
PnPConnection.Current.Context.ExecuteQueryRetry();
1818
foreach (var ct in result.Where(l => l.Name.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)))
1919
{
20-
yield return new CompletionResult($"\"{ct.Name}\"");
20+
yield return new CompletionResult($"{quoteChar}{ct.Name}{quoteChar}");
2121
}
2222
}
2323
}

src/Commands/Base/Completers/FieldInternalNameCompleter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@ namespace PnP.PowerShell.Commands.Base.Completers
1111
{
1212
public sealed class FieldInternalNameCompleter : PnPArgumentCompleter
1313
{
14-
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
14+
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar)
1515
{
1616
IEnumerable<Field> result = PnPConnection.Current.Context.LoadQuery(PnPConnection.Current.Context.Web.AvailableFields.Include(f => f.InternalName));
1717
PnPConnection.Current.Context.ExecuteQueryRetry();
1818
foreach (var field in result.Where(l => l.InternalName.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)))
1919
{
20-
yield return new CompletionResult($"\"{field.InternalName}\"");
20+
yield return new CompletionResult($"{quoteChar}{field.InternalName}{quoteChar}");
2121
}
2222
}
2323
}

src/Commands/Base/Completers/ListNameCompleter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -10,13 +10,18 @@ namespace PnP.PowerShell.Commands.Base.Completers
1010
{
1111
public sealed class ListNameCompleter : PnPArgumentCompleter
1212
{
13-
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
13+
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar)
1414
{
1515
IEnumerable<List> result = PnPConnection.Current.Context.LoadQuery(PnPConnection.Current.Context.Web.Lists.Include(list => list.Title));
1616
PnPConnection.Current.Context.ExecuteQueryRetry();
1717
foreach (var list in result.Where(l => l.Title.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)))
1818
{
19-
yield return new CompletionResult($"\"{list.Title.Replace("\"","`\"")}\"");
19+
var listTitle = list.Title;
20+
if(quoteChar == '"')
21+
{
22+
listTitle = list.Title.Replace("\"","`\"");
23+
}
24+
yield return new CompletionResult($"{quoteChar}{listTitle}{quoteChar}");
2025
}
2126

2227
}

src/Commands/Base/Completers/PageCompleter.cs

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -16,15 +16,15 @@ namespace PnP.PowerShell.Commands.Base.Completers
1616
{
1717
public sealed class PageCompleter : PnPArgumentCompleter
1818
{
19-
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
19+
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar)
2020
{
2121
List<CompletionResult> results = new List<CompletionResult>();
2222
wordToComplete = wordToComplete.Replace('\\', '/');
2323
var pages = PnPConnection.Current.PnPContext.Web.GetPages(wordToComplete.TrimStart('/'));
2424
foreach (var page in pages.OrderBy(p => p.Name))
2525
{
2626
var result = string.IsNullOrEmpty(page.Folder) ? page.Name : page.Folder + "/" + page.Name;
27-
results.Add(new CompletionResult($"\"{result}\""));
27+
results.Add(new CompletionResult($"{quoteChar}{result}{quoteChar}"));
2828
}
2929
return results;
3030
}

src/Commands/Base/Completers/PnPArgumentCompleter.cs

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -12,12 +12,17 @@ public abstract class PnPArgumentCompleter : IArgumentCompleter
1212
private const int Timeout = 2000;
1313
public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
1414
{
15+
var quoteChar = '"';
16+
if(wordToComplete.StartsWith('\''))
17+
{
18+
quoteChar = '\'';
19+
}
1520
wordToComplete = wordToComplete.Trim(['"', '\'']);
16-
var task = Task.Run(() => GetArguments(commandName, parameterName, wordToComplete, commandAst, fakeBoundParameters));
21+
var task = Task.Run(() => GetArguments(commandName, parameterName, wordToComplete, commandAst, fakeBoundParameters, quoteChar));
1722
return task.TimeoutAfter(TimeSpan.FromMilliseconds(GetTimeOut())).GetAwaiter().GetResult();
1823
}
1924

20-
public abstract IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters);
25+
public abstract IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar);
2126

2227
private Int32 GetTimeOut()
2328
{

src/Commands/Base/Completers/PropertyBagKeyCompleter.cs

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -10,9 +10,9 @@
1010

1111
namespace PnP.PowerShell.Commands.Base.Completers
1212
{
13-
public sealed class PropertyBagKeyCompleter : IArgumentCompleter
13+
public sealed class PropertyBagKeyCompleter : PnPArgumentCompleter
1414
{
15-
public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters)
15+
public override IEnumerable<CompletionResult> GetArguments(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters, char quoteChar)
1616
{
1717
IEnumerable<string> keys = null;
1818
if (fakeBoundParameters["Folder"] == null)
@@ -36,7 +36,7 @@ public IEnumerable<CompletionResult> CompleteArgument(string commandName, string
3636

3737
foreach (var key in keys.Where(k => k.StartsWith(wordToComplete, StringComparison.InvariantCultureIgnoreCase)))
3838
{
39-
yield return new CompletionResult($"\"{key}\"");
39+
yield return new CompletionResult($"{quoteChar}{key}{quoteChar}");
4040
}
4141
}
4242
}

0 commit comments

Comments
 (0)