From d2d3b83bff27ff62aaa3c0246ab6b11a37f530f5 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Mon, 26 Oct 2020 13:17:06 -0700 Subject: [PATCH 1/2] Format search values. --- src/readme.graph.md | 4 ++++ tools/Custom/ListCmdlet.cs | 20 ++++++++++++++++++++ 2 files changed, 24 insertions(+) diff --git a/src/readme.graph.md b/src/readme.graph.md index 413b58a76f1..bee31d90e98 100644 --- a/src/readme.graph.md +++ b/src/readme.graph.md @@ -551,6 +551,10 @@ directive: // Call OnBeforeWriteObject to deserialize '@odata.count' from the response object. let writeObjectRegex = /^(\s*)(WriteObject\(result\.Value,true\);)$/gm $ = $.replace(writeObjectRegex,'\n$1OnBeforeWriteObject(this.InvocationInformation.BoundParameters, result?.AdditionalProperties);\n$1$2'); + + // Format all Search values by adding quotes around them. + let searchQueryRegex = /this\.InvocationInformation\.BoundParameters\.ContainsKey\("Search"\)\s*\?\s*Search\s*:\s*null/gm + $ = $.replace(searchQueryRegex, 'this.FormatSearchValue(this.InvocationInformation.BoundParameters, Search)'); } return $; } diff --git a/tools/Custom/ListCmdlet.cs b/tools/Custom/ListCmdlet.cs index 6f23b15201b..7a54d685065 100644 --- a/tools/Custom/ListCmdlet.cs +++ b/tools/Custom/ListCmdlet.cs @@ -172,6 +172,26 @@ public bool ShouldIteratePages(global::System.Collections.Generic.Dictionary + /// Adds quote marks around $search values if non exists. + /// + /// The bound parameters of the calling cmdlet. + /// The $search value. + /// A formated search values. + internal string FormatSearchValue(global::System.Collections.Generic.Dictionary boundParameters, string search) + { + if (!boundParameters.ContainsKey("Search")) + { + return null; + } + else if (!string.IsNullOrWhiteSpace(search) && !search.StartsWith("\"")) + { + search = $"\"{search}\""; + } + + return search; + } + internal void OnBeforeWriteObject(global::System.Collections.Generic.Dictionary boundParameters, global::System.Collections.Generic.IDictionary additionalProperties) { // Get odata.count from the response. From ecd79e112f0f75e53ee5347904544b5fd165e314 Mon Sep 17 00:00:00 2001 From: Peter Ombwa Date: Tue, 27 Oct 2020 10:36:39 -0700 Subject: [PATCH 2/2] Update comments. --- tools/Custom/ListCmdlet.cs | 5 +++-- 1 file changed, 3 insertions(+), 2 deletions(-) diff --git a/tools/Custom/ListCmdlet.cs b/tools/Custom/ListCmdlet.cs index 7a54d685065..13660faf15f 100644 --- a/tools/Custom/ListCmdlet.cs +++ b/tools/Custom/ListCmdlet.cs @@ -173,11 +173,12 @@ public bool ShouldIteratePages(global::System.Collections.Generic.Dictionary - /// Adds quote marks around $search values if non exists. + /// Adds quotation mark around $search values if none exists. + /// This is needed to support KQL e.g. "prop:value". /// /// The bound parameters of the calling cmdlet. /// The $search value. - /// A formated search values. + /// A formated search value. internal string FormatSearchValue(global::System.Collections.Generic.Dictionary boundParameters, string search) { if (!boundParameters.ContainsKey("Search"))