From c0d4d9fcc4bed19a585e1dea5f25b9e32eb72f24 Mon Sep 17 00:00:00 2001 From: Maoliang Huang Date: Wed, 17 Feb 2021 11:17:53 -0800 Subject: [PATCH] Update the cmdlet parameters according to feedback. --- .../Commands/DisableAzPredictor.cs | 10 +++--- .../Commands/EnableAzPredictor.cs | 10 +++--- .../Commands/SessionParameterValue.cs | 32 ------------------- 3 files changed, 8 insertions(+), 44 deletions(-) delete mode 100644 tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/SessionParameterValue.cs diff --git a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/DisableAzPredictor.cs b/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/DisableAzPredictor.cs index d99005a21e20..72a230ae46cc 100644 --- a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/DisableAzPredictor.cs +++ b/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/DisableAzPredictor.cs @@ -12,7 +12,6 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; using System.Text; using System.Management.Automation; @@ -29,11 +28,10 @@ public sealed class DisableAzPredictor : PSCmdlet }; /// - /// Gets and sets the session that this cmdlet applies to. + /// Indicates whether it's applied to all sessions. /// - [Parameter(Position = 0)] - [ValidateSet(nameof(SessionParameterValue.All), nameof(SessionParameterValue.Current))] - public SessionParameterValue Session { get; set; } + [Parameter(Mandatory = false)] + public SwitchParameter AllSession { get; set; } /// /// Indicates whether the user would like to receive output. @@ -47,7 +45,7 @@ protected override void ProcessRecord() var scriptToRun = new StringBuilder(); var _ = scriptToRun.Append(DisableAzPredictor._DisableStatements[0]); - if (Session == SessionParameterValue.All) + if (AllSession.IsPresent) { _ = scriptToRun.Append(";Write-Host \"To disable Az Predictor, please edit your profile ($PROFILE) and remove the following lines:`nImport-Module Az.Tools.Predictor`nSet-PSReadLineOption -PredictionSource HistoryAndPlugin`n\""); } diff --git a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/EnableAzPredictor.cs b/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/EnableAzPredictor.cs index 607ef36bef63..b01c70734e7b 100644 --- a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/EnableAzPredictor.cs +++ b/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/EnableAzPredictor.cs @@ -12,7 +12,6 @@ // limitations under the License. // ---------------------------------------------------------------------------------- -using System; using System.Text; using System.Management.Automation; @@ -30,11 +29,10 @@ public sealed class EnableAzPredictor : PSCmdlet }; /// - /// Gets and sets the session that this cmdlet applies to. + /// Indicates whether it's applied to all sessions. /// - [Parameter(Position = 0)] - [ValidateSet(nameof(SessionParameterValue.All), nameof(SessionParameterValue.Current))] - public SessionParameterValue Session { get; set; } + [Parameter(Mandatory = false)] + public SwitchParameter AllSession { get; set; } /// /// Indicates whether the user would like to receive output. @@ -48,7 +46,7 @@ protected override void ProcessRecord() var scriptToRun = new StringBuilder(); var _ = scriptToRun.Append(EnableAzPredictor._EnableStatements[1]); - if (Session == SessionParameterValue.All) + if (AllSession.IsPresent) { _ = scriptToRun.Append($";Add-Content -Path $PROFILE -Value \"`n{string.Join("`n", EnableAzPredictor._EnableStatements)}\" -NoNewline -Encoding UTF8 -Force") .Append($";Write-Host \"User profile ($PROFILE) has been updated.`n\""); diff --git a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/SessionParameterValue.cs b/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/SessionParameterValue.cs deleted file mode 100644 index 431899cfeb35..000000000000 --- a/tools/Az.Tools.Predictor/Az.Tools.Predictor/Commands/SessionParameterValue.cs +++ /dev/null @@ -1,32 +0,0 @@ -// ---------------------------------------------------------------------------------- -// -// Copyright Microsoft Corporation -// Licensed under the Apache License, Version 2.0 (the "License"); -// you may not use this file except in compliance with the License. -// You may obtain a copy of the License at -// http://www.apache.org/licenses/LICENSE-2.0 -// Unless required by applicable law or agreed to in writing, software -// distributed under the License is distributed on an "AS IS" BASIS, -// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. -// See the License for the specific language governing permissions and -// limitations under the License. -// ---------------------------------------------------------------------------------- - -namespace Microsoft.Azure.PowerShell.Tools.AzPredictor -{ - /// - /// The value used in the parameter -Session in the cmdlets. - /// - public enum SessionParameterValue - { - /// - /// All the session. - /// - All, - - /// - /// The current session. - /// - Current - } -}