Skip to content

Commit b197961

Browse files
authored
WinGetPackage DSC Resource (microsoft#2863)
This is a preview implementation of a DSC resource that installs packages on winget. For now, ensures a package is installed or not. Its install behavior depends if the package is already installed for the user or not.
1 parent f269007 commit b197961

27 files changed

Lines changed: 520 additions & 59 deletions

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/FinderCmdlet.cs

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -8,6 +8,7 @@ namespace Microsoft.WinGet.Client.Commands.Common
88
{
99
using System.Management.Automation;
1010
using Microsoft.WinGet.Client.Common;
11+
using Microsoft.WinGet.Client.PSObjects;
1112

1213
/// <summary>
1314
/// This is the base class for all commands that might need to search for a package. It contains an initial
@@ -58,11 +59,11 @@ public abstract class FinderCmdlet : PSCmdlet
5859
public string[] Query { get; set; }
5960

6061
/// <summary>
61-
/// Gets or sets a value indicating whether to match exactly against package fields.
62+
/// Gets or sets how to match against package fields. Default ContainsCaseInsensitive.
6263
/// </summary>
6364
[Parameter(
6465
ParameterSetName = Constants.FoundSet,
6566
ValueFromPipelineByPropertyName = true)]
66-
public SwitchParameter Exact { get; set; }
67+
public PSPackageFieldMatchOption MatchOption { get; set; } = PSPackageFieldMatchOption.ContainsCaseInsensitive;
6768
}
6869
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/Common/InstallCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ namespace Microsoft.WinGet.Client.Commands.Common
88
{
99
using System.IO;
1010
using System.Management.Automation;
11-
using Microsoft.WinGet.Client.Engine.PSObjects;
11+
using Microsoft.WinGet.Client.PSObjects;
1212

1313
/// <summary>
1414
/// This is the base class for all commands that parse a FindPackagesOptions result

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/FindPackageCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected override void ProcessRecord()
3131
this.Moniker,
3232
this.Source,
3333
this.Query,
34-
this.Exact.ToBool(),
34+
this.MatchOption.ToString(),
3535
this.Tag,
3636
this.Command,
3737
this.Count);

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/GetPackageCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ protected override void ProcessRecord()
3131
this.Moniker,
3232
this.Source,
3333
this.Query,
34-
this.Exact.ToBool(),
34+
this.MatchOption.ToString(),
3535
this.Tag,
3636
this.Command,
3737
this.Count);

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/InstallPackageCmdlet.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace Microsoft.WinGet.Client.Commands
88
{
9-
using System.Management.Automation;
10-
using Microsoft.WinGet.Client.Commands.Common;
11-
using Microsoft.WinGet.Client.Common;
12-
using Microsoft.WinGet.Client.Engine.Commands;
9+
using System.Management.Automation;
10+
using Microsoft.WinGet.Client.Commands.Common;
11+
using Microsoft.WinGet.Client.Common;
12+
using Microsoft.WinGet.Client.Engine.Commands;
1313
using Microsoft.WinGet.Client.Engine.PSObjects;
14+
using Microsoft.WinGet.Client.PSObjects;
1415

1516
/// <summary>
1617
/// Installs a package from the pipeline or from a configured source.
@@ -57,7 +58,7 @@ protected override void ProcessRecord()
5758
this.Moniker,
5859
this.Source,
5960
this.Query,
60-
this.Exact.ToBool());
61+
this.MatchOption.ToString());
6162
command.Install(this.Scope.ToString(), this.Architecture.ToString());
6263
}
6364
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UninstallPackageCmdlet.cs

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -6,11 +6,12 @@
66

77
namespace Microsoft.WinGet.Client.Commands
88
{
9-
using System.Management.Automation;
10-
using Microsoft.WinGet.Client.Commands.Common;
11-
using Microsoft.WinGet.Client.Common;
12-
using Microsoft.WinGet.Client.Engine.Commands;
9+
using System.Management.Automation;
10+
using Microsoft.WinGet.Client.Commands.Common;
11+
using Microsoft.WinGet.Client.Common;
12+
using Microsoft.WinGet.Client.Engine.Commands;
1313
using Microsoft.WinGet.Client.Engine.PSObjects;
14+
using Microsoft.WinGet.Client.PSObjects;
1415

1516
/// <summary>
1617
/// Uninstalls a package from the local system.
@@ -50,7 +51,7 @@ protected override void ProcessRecord()
5051
this.Moniker,
5152
this.Source,
5253
this.Query,
53-
this.Exact.ToBool());
54+
this.MatchOption.ToString());
5455
command.Uninstall(this.Mode.ToString(), this.Force.ToBool());
5556
}
5657
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/Cmdlets/UpdatePackageCmdlet.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,7 @@ protected override void ProcessRecord()
5151
this.Moniker,
5252
this.Source,
5353
this.Query,
54-
this.Exact.ToBool());
54+
this.MatchOption.ToString());
5555
command.Update(this.IncludeUnknown.ToBool());
5656
}
5757
}
Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,34 @@
1+
// -----------------------------------------------------------------------------
2+
// <copyright file="PSPackageFieldMatchOption.cs" company="Microsoft Corporation">
3+
// Copyright (c) Microsoft Corporation. Licensed under the MIT License.
4+
// </copyright>
5+
// -----------------------------------------------------------------------------
6+
7+
namespace Microsoft.WinGet.Client.PSObjects
8+
{
9+
/// <summary>
10+
/// This should mimic Microsoft.Management.Deployment.PackageFileMatchOption.
11+
/// </summary>
12+
public enum PSPackageFieldMatchOption
13+
{
14+
/// <summary>
15+
/// Equals.
16+
/// </summary>
17+
Equals,
18+
19+
/// <summary>
20+
/// EqualsCaseInsensitive.
21+
/// </summary>
22+
EqualsCaseInsensitive,
23+
24+
/// <summary>
25+
/// StartsWithCaseInsensitive.
26+
/// </summary>
27+
StartsWithCaseInsensitive,
28+
29+
/// <summary>
30+
/// ContainsCaseInsensitive
31+
/// </summary>
32+
ContainsCaseInsensitive,
33+
}
34+
}

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/PSObjects/PSPackageInstallMode.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// </copyright>
55
// -----------------------------------------------------------------------------
66

7-
namespace Microsoft.WinGet.Client.Engine.PSObjects
7+
namespace Microsoft.WinGet.Client.PSObjects
88
{
99
/// <summary>
1010
/// This should mimic Microsoft.Management.Deployment.PackageInstallMode.

src/PowerShell/Microsoft.WinGet.Client.Cmdlets/PSObjects/PSPackageInstallScope.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,7 +4,7 @@
44
// </copyright>
55
// -----------------------------------------------------------------------------
66

7-
namespace Microsoft.WinGet.Client.Engine.PSObjects
7+
namespace Microsoft.WinGet.Client.PSObjects
88
{
99
/// <summary>
1010
/// This must match Microsoft.Management.Deployment.PackageInstallScope.

0 commit comments

Comments
 (0)