-
Notifications
You must be signed in to change notification settings - Fork 8.1k
Add Enable-ExperimentalFeature and Disable-ExperimentalFeature cmdlets
#8318
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Merged
daxian-dbw
merged 20 commits into
PowerShell:master
from
SteveL-MSFT:experimental-feature-cmdlets
Dec 5, 2018
Merged
Changes from all commits
Commits
Show all changes
20 commits
Select commit
Hold shift + click to select a range
8c585f6
[feature]
SteveL-MSFT 02f566b
[feature]
SteveL-MSFT 6d290b4
[feature]
SteveL-MSFT 6727dd7
[feature]
SteveL-MSFT 745a91b
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov e8218a3
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 3f737e5
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 0fd3980
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 596afc7
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov ce871df
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 7269cf6
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 903ea39
address Ilya's feedback
SteveL-MSFT ecf82cf
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 890a412
Update test/powershell/engine/ExperimentalFeature/Get-ExperimentalFea…
iSazonov 3b8d53e
add helpuri
SteveL-MSFT 34e020b
change fwdlink for get-experimentalfeature to original
SteveL-MSFT 0508fdd
Update src/System.Management.Automation/engine/ExperimentalFeature/En…
iSazonov 8de4efe
Update src/System.Management.Automation/engine/ExperimentalFeature/En…
vexx32 86b56a2
[feature]
SteveL-MSFT 93be24e
[feature]
SteveL-MSFT File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
131 changes: 131 additions & 0 deletions
131
...nagement.Automation/engine/ExperimentalFeature/EnableDisableExperimentalFeatureCommand.cs
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,131 @@ | ||
| // Copyright (c) Microsoft Corporation. All rights reserved. | ||
| // Licensed under the MIT License. | ||
|
|
||
| using System; | ||
| using System.Collections; | ||
| using System.Collections.Generic; | ||
| using System.Globalization; | ||
| using System.Linq; | ||
| using System.Management.Automation; | ||
| using System.Management.Automation.Configuration; | ||
| using System.Management.Automation.Internal; | ||
| using System.Management.Automation.Language; | ||
|
|
||
| namespace Microsoft.PowerShell.Commands | ||
| { | ||
| /// <summary> | ||
| /// Base class for Enable/Disable-ExperimentalFeature cmdlet. | ||
| /// </summary> | ||
| public class EnableDisableExperimentalFeatureCommandBase : PSCmdlet | ||
| { | ||
| /// <summary> | ||
| /// Gets or sets the feature names. | ||
| /// </summary> | ||
| [Parameter(ValueFromPipelineByPropertyName = true, Position = 0, Mandatory = true)] | ||
| [ArgumentCompleter(typeof(ExperimentalFeatureNameCompleter))] | ||
| public string[] Name { get; set; } | ||
|
|
||
| /// <summary> | ||
| /// Gets or sets the scope of persistence of updating the PowerShell configuration json. | ||
| /// </summary> | ||
| [Parameter] | ||
| public ConfigScope Scope { get; set; } = ConfigScope.CurrentUser; | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Implements Enable-ExperimentalFeature cmdlet. | ||
| /// </summary> | ||
| [Cmdlet(VerbsLifecycle.Enable, "ExperimentalFeature", SupportsShouldProcess = true, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2046964")] | ||
| public class EnableExperimentalFeatureCommand : EnableDisableExperimentalFeatureCommandBase | ||
| { | ||
| /// <summary> | ||
| /// ProcessRecord method of this cmdlet. | ||
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| ExperimentalFeatureConfigHelper.UpdateConfig(this, Name, Scope, enable: true); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Implements Enable-ExperimentalFeature cmdlet. | ||
| /// </summary> | ||
| [Cmdlet(VerbsLifecycle.Disable, "ExperimentalFeature", SupportsShouldProcess = true, HelpUri = "https://go.microsoft.com/fwlink/?LinkID=2046963")] | ||
| public class DisableExperimentalFeatureCommand : EnableDisableExperimentalFeatureCommandBase | ||
| { | ||
| /// <summary> | ||
| /// ProcessRecord method of this cmdlet. | ||
| /// </summary> | ||
| protected override void ProcessRecord() | ||
| { | ||
| ExperimentalFeatureConfigHelper.UpdateConfig(this, Name, Scope, enable: false); | ||
| } | ||
| } | ||
|
|
||
| internal class ExperimentalFeatureConfigHelper | ||
| { | ||
| internal static void UpdateConfig(PSCmdlet cmdlet, string[] name, ConfigScope scope, bool enable) | ||
| { | ||
| IEnumerable<WildcardPattern> namePatterns = SessionStateUtilities.CreateWildcardsFromStrings(name, WildcardOptions.IgnoreCase | WildcardOptions.CultureInvariant); | ||
| GetExperimentalFeatureCommand getExperimentalFeatureCommand = new GetExperimentalFeatureCommand(); | ||
| getExperimentalFeatureCommand.Context = cmdlet.Context; | ||
| bool foundFeature = false; | ||
| foreach (ExperimentalFeature feature in getExperimentalFeatureCommand.GetAvailableExperimentalFeatures(namePatterns)) | ||
| { | ||
| foundFeature = true; | ||
| if (!cmdlet.ShouldProcess(feature.Name)) | ||
| { | ||
| return; | ||
| } | ||
|
|
||
| PowerShellConfig.Instance.SetExperimentalFeatures(scope, feature.Name, enable); | ||
| } | ||
|
|
||
| if (!foundFeature) | ||
| { | ||
| string errMsg = string.Format(CultureInfo.InvariantCulture, ExperimentalFeatureStrings.ExperimentalFeatureNameNotFound, name); | ||
| cmdlet.WriteError(new ErrorRecord(new ItemNotFoundException(errMsg), "ItemNotFoundException", ErrorCategory.ObjectNotFound, name)); | ||
| return; | ||
| } | ||
|
|
||
| cmdlet.WriteWarning(ExperimentalFeatureStrings.ExperimentalFeaturePending); | ||
| } | ||
| } | ||
|
|
||
| /// <summary> | ||
| /// Provides argument completion for ExperimentalFeature names. | ||
| /// </summary> | ||
| public class ExperimentalFeatureNameCompleter : IArgumentCompleter | ||
| { | ||
| /// <summary> | ||
| /// Returns completion results for experimental feature names used as arguments to experimental feature cmdlets. | ||
| /// </summary> | ||
| /// <param name="commandName">The command name.</param> | ||
| /// <param name="parameterName">The parameter name.</param> | ||
| /// <param name="wordToComplete">The word to complete.</param> | ||
| /// <param name="commandAst">The command AST.</param> | ||
| /// <param name="fakeBoundParameters">The fake bound parameters.</param> | ||
| /// <returns>List of Completion Results.</returns> | ||
| public IEnumerable<CompletionResult> CompleteArgument(string commandName, string parameterName, string wordToComplete, CommandAst commandAst, IDictionary fakeBoundParameters) | ||
| { | ||
| if (fakeBoundParameters == null) | ||
| { | ||
| throw PSTraceSource.NewArgumentNullException(nameof(fakeBoundParameters)); | ||
| } | ||
|
|
||
| var commandInfo = new CmdletInfo("Get-ExperimentalFeature", typeof(GetExperimentalFeatureCommand)); | ||
SteveL-MSFT marked this conversation as resolved.
Outdated
Show resolved
Hide resolved
|
||
| var ps = System.Management.Automation.PowerShell.Create(RunspaceMode.CurrentRunspace) | ||
| .AddCommand(commandInfo) | ||
| .AddParameter("Name", wordToComplete + "*"); | ||
|
|
||
| HashSet<string> names = new HashSet<string>(); | ||
| var results = ps.Invoke<ExperimentalFeature>(); | ||
| foreach (var result in results) | ||
SteveL-MSFT marked this conversation as resolved.
Show resolved
Hide resolved
|
||
| { | ||
| names.Add(result.Name); | ||
| } | ||
|
|
||
| return names.OrderBy(name => name).Select(name => new CompletionResult(name, name, CompletionResultType.Text, name)); | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.