Skip to content

Commit

Permalink
Improved VSCode packaging #1755 (#1756)
Browse files Browse the repository at this point in the history
  • Loading branch information
BernieWhite authored Feb 13, 2024
1 parent 308a89b commit 49d1193
Show file tree
Hide file tree
Showing 24 changed files with 3,249 additions and 146 deletions.
16 changes: 11 additions & 5 deletions PSRule.sln
Original file line number Diff line number Diff line change
Expand Up @@ -15,7 +15,7 @@ Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.BuildTool", "src\PSR
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.SDK", "src\PSRule.SDK\PSRule.SDK.csproj", "{07A84E67-1CA3-4766-B9EA-1FDD9DF6516F}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.Tool", "src\PSRule.Tool\PSRule.Tool.csproj", "{F6CFCA60-72D5-474E-8B8B-1AB973434569}"
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.Tool", "src\PSRule.Tool\PSRule.Tool.csproj", "{BDDBFDB8-614F-4B8A-930C-DCB60144598C}"
EndProject
Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "Solution Items", "Solution Items", "{F5173A23-CCEA-4C39-AB8D-EF6E86C11BD7}"
ProjectSection(SolutionItems) = preProject
Expand All @@ -30,6 +30,8 @@ Project("{2150E333-8FDC-42A3-9474-1A3956D46DE8}") = "tests", "tests", "{E0EA0CBA
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.Tool.Tests", "tests\PSRule.Tool.Tests\PSRule.Tool.Tests.csproj", "{DA46C891-08F1-4D01-9F98-1F8BB10CAFEC}"
EndProject
Project("{9A19103F-16F7-4668-BE54-9A1E7A4F7556}") = "PSRule.CommandLine", "src\PSRule.CommandLine\PSRule.CommandLine.csproj", "{9A556814-8E9D-4C76-8F6D-1AF2DA23A9E0}"
EndProject
Global
GlobalSection(SolutionConfigurationPlatforms) = preSolution
Debug|Any CPU = Debug|Any CPU
Expand Down Expand Up @@ -60,10 +62,10 @@ Global
{07A84E67-1CA3-4766-B9EA-1FDD9DF6516F}.Debug|Any CPU.Build.0 = Debug|Any CPU
{07A84E67-1CA3-4766-B9EA-1FDD9DF6516F}.Release|Any CPU.ActiveCfg = Release|Any CPU
{07A84E67-1CA3-4766-B9EA-1FDD9DF6516F}.Release|Any CPU.Build.0 = Release|Any CPU
{F6CFCA60-72D5-474E-8B8B-1AB973434569}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{F6CFCA60-72D5-474E-8B8B-1AB973434569}.Debug|Any CPU.Build.0 = Debug|Any CPU
{F6CFCA60-72D5-474E-8B8B-1AB973434569}.Release|Any CPU.ActiveCfg = Release|Any CPU
{F6CFCA60-72D5-474E-8B8B-1AB973434569}.Release|Any CPU.Build.0 = Release|Any CPU
{BDDBFDB8-614F-4B8A-930C-DCB60144598C}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{BDDBFDB8-614F-4B8A-930C-DCB60144598C}.Debug|Any CPU.Build.0 = Debug|Any CPU
{BDDBFDB8-614F-4B8A-930C-DCB60144598C}.Release|Any CPU.ActiveCfg = Release|Any CPU
{BDDBFDB8-614F-4B8A-930C-DCB60144598C}.Release|Any CPU.Build.0 = Release|Any CPU
{5FE4DB0B-63D1-4DDB-9762-9C0D29168BC9}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{5FE4DB0B-63D1-4DDB-9762-9C0D29168BC9}.Debug|Any CPU.Build.0 = Debug|Any CPU
{5FE4DB0B-63D1-4DDB-9762-9C0D29168BC9}.Release|Any CPU.ActiveCfg = Release|Any CPU
Expand All @@ -76,6 +78,10 @@ Global
{DA46C891-08F1-4D01-9F98-1F8BB10CAFEC}.Debug|Any CPU.Build.0 = Debug|Any CPU
{DA46C891-08F1-4D01-9F98-1F8BB10CAFEC}.Release|Any CPU.ActiveCfg = Release|Any CPU
{DA46C891-08F1-4D01-9F98-1F8BB10CAFEC}.Release|Any CPU.Build.0 = Release|Any CPU
{9A556814-8E9D-4C76-8F6D-1AF2DA23A9E0}.Debug|Any CPU.ActiveCfg = Debug|Any CPU
{9A556814-8E9D-4C76-8F6D-1AF2DA23A9E0}.Debug|Any CPU.Build.0 = Debug|Any CPU
{9A556814-8E9D-4C76-8F6D-1AF2DA23A9E0}.Release|Any CPU.ActiveCfg = Release|Any CPU
{9A556814-8E9D-4C76-8F6D-1AF2DA23A9E0}.Release|Any CPU.Build.0 = Release|Any CPU
EndGlobalSection
GlobalSection(SolutionProperties) = preSolution
HideSolutionNode = FALSE
Expand Down
3 changes: 3 additions & 0 deletions docs/CHANGELOG-v3.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,9 @@ See [upgrade notes][1] for helpful information when upgrading from previous vers

What's changed since pre-release v3.0.0-B0141:

- General improvements:
- Improved support for packaging with Visual Studio Code by @BernieWhite.
[#1755](https://github.com/microsoft/PSRule/issues/1755)
- Engineering:
- **Breaking change:** Bump development tools to .NET 8.0 SDK by @BernieWhite.
[#1673](https://github.com/microsoft/PSRule/pull/1673)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,10 +4,21 @@
using System.CommandLine.Invocation;
using PSRule.Configuration;

namespace PSRule.Tool;
namespace PSRule.CommandLine;

internal sealed class ClientContext
/// <summary>
///
/// </summary>
public sealed class ClientContext
{
/// <summary>
///
/// </summary>
/// <param name="invocation"></param>
/// <param name="option"></param>
/// <param name="verbose"></param>
/// <param name="debug"></param>
/// <exception cref="ArgumentNullException"></exception>
public ClientContext(InvocationContext invocation, string? option, bool verbose, bool debug)
{
Path = AppDomain.CurrentDomain.BaseDirectory;
Expand All @@ -18,16 +29,34 @@ public ClientContext(InvocationContext invocation, string? option, bool verbose,
Option = GetOption(Host, option);
}

/// <summary>
///
/// </summary>
public string Path { get; }

/// <summary>
///
/// </summary>
public InvocationContext Invocation { get; }

/// <summary>
///
/// </summary>
public ClientHost Host { get; }

/// <summary>
///
/// </summary>
public PSRuleOption Option { get; }

/// <summary>
///
/// </summary>
public bool Verbose { get; }

/// <summary>
///
/// </summary>
public bool Debug { get; }

private static PSRuleOption GetOption(ClientHost host, string? path)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@
using System.CommandLine;
using System.CommandLine.IO;

namespace PSRule.Tool;
namespace PSRule.CommandLine;

internal static class ClientContextExtensions
{
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,25 @@
using System.Management.Automation;
using PSRule.Pipeline;

namespace PSRule.Tool;
namespace PSRule.CommandLine;

internal sealed class ClientHost : HostContext
/// <summary>
///
/// </summary>
public sealed class ClientHost : HostContext
{
private readonly ClientContext _Context;
private readonly bool _Verbose;
private readonly bool _Debug;
private readonly ConsoleColor _BackgroundColor;
private readonly ConsoleColor _ForegroundColor;

/// <summary>
///
/// </summary>
/// <param name="context"></param>
/// <param name="verbose"></param>
/// <param name="debug"></param>
public ClientHost(ClientContext context, bool verbose, bool debug)
{
_Context = context;
Expand All @@ -27,6 +36,11 @@ public ClientHost(ClientContext context, bool verbose, bool debug)
Verbose($"Using working path: {Directory.GetCurrentDirectory()}");
}

/// <summary>
///
/// </summary>
/// <param name="variableName"></param>
/// <returns></returns>
public override ActionPreference GetPreferenceVariable(string variableName)
{
if (variableName == "VerbosePreference")
Expand All @@ -38,22 +52,40 @@ public override ActionPreference GetPreferenceVariable(string variableName)
return base.GetPreferenceVariable(variableName);
}

/// <summary>
///
/// </summary>
/// <param name="errorRecord"></param>
public override void Error(ErrorRecord errorRecord)
{
_Context.LogError(errorRecord.Exception.Message);
base.Error(errorRecord);
}

/// <summary>
///
/// </summary>
/// <param name="text"></param>
public override void Warning(string text)
{
_Context.Invocation.Console.WriteLine(text);
}

/// <summary>
///
/// </summary>
/// <param name="target"></param>
/// <param name="action"></param>
/// <returns></returns>
public override bool ShouldProcess(string target, string action)
{
return true;
}

/// <summary>
///
/// </summary>
/// <param name="informationRecord"></param>
public override void Information(InformationRecord informationRecord)
{
if (informationRecord?.MessageData is HostInformationMessage info)
Expand All @@ -80,6 +112,10 @@ private void RevertConsole()
Console.ForegroundColor = _ForegroundColor;
}

/// <summary>
///
/// </summary>
/// <param name="text"></param>
public override void Verbose(string text)
{
if (!_Verbose)
Expand All @@ -88,6 +124,10 @@ public override void Verbose(string text)
_Context.LogVerbose(text);
}

/// <summary>
///
/// </summary>
/// <param name="text"></param>
public override void Debug(string text)
{
if (!_Debug)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,19 +5,19 @@
using System.Diagnostics.CodeAnalysis;
using System.Management.Automation;
using Newtonsoft.Json;
using PSRule.CommandLine.Resources;
using PSRule.Configuration;
using PSRule.Data;
using PSRule.Pipeline.Dependencies;
using PSRule.Tool.Models;
using PSRule.Tool.Resources;
using PSRule.CommandLine.Models;
using SemanticVersion = PSRule.Data.SemanticVersion;

namespace PSRule.Tool.Commands;
namespace PSRule.CommandLine.Commands;

/// <summary>
/// Execute features of the <c>module</c> command through the CLI.
/// </summary>
internal sealed class ModuleCommand
public sealed class ModuleCommand
{
/// <summary>
/// Failed to install a module.
Expand All @@ -35,6 +35,9 @@ internal sealed class ModuleCommand
private const string FIELD_PSDATA = "PSData";
private const string PRERELEASE_SEPARATOR = "-";

/// <summary>
/// Call <c>module restore</c>.
/// </summary>
public static int ModuleRestore(RestoreOptions operationOptions, ClientContext clientContext)
{
var exitCode = 0;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,17 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

using PSRule.CommandLine.Models;
using PSRule.Configuration;
using PSRule.Pipeline;
using PSRule.Pipeline.Dependencies;
using PSRule.Tool.Models;

namespace PSRule.Tool.Commands;
namespace PSRule.CommandLine.Commands;

/// <summary>
/// Execute features of the <c>run</c> command through the CLI.
/// </summary>
internal sealed class RunCommand
public sealed class RunCommand
{
private const string PUBLISHER = "CN=Microsoft Corporation, O=Microsoft Corporation, L=Redmond, S=Washington, C=US";

Expand All @@ -25,12 +25,15 @@ internal sealed class RunCommand
/// </summary>
private const int ERROR_BREAK_ON_FAILURE = 100;

/// <summary>
/// Call <c>run</c>.
/// </summary>
public static int Run(RunOptions operationOptions, ClientContext clientContext)
{
var exitCode = 0;
var file = LockFile.Read(null);
var inputPath = operationOptions.InputPath == null || operationOptions.InputPath.Length == 0 ?
new string[] { Environment.GetWorkingPath() } : operationOptions.InputPath;
[Environment.GetWorkingPath()] : operationOptions.InputPath;

if (operationOptions.Path != null)
clientContext.Option.Include.Path = operationOptions.Path;
Expand Down
35 changes: 35 additions & 0 deletions src/PSRule.CommandLine/Models/ModuleOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,35 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace PSRule.CommandLine.Models;

/// <summary>
///
/// </summary>
public sealed class ModuleOptions
{
/// <summary>
///
/// </summary>
public string[]? Path { get; set; }

/// <summary>
///
/// </summary>
public string[]? Module { get; set; }

/// <summary>
///
/// </summary>
public bool Force { get; set; }

/// <summary>
///
/// </summary>
public string? Version { get; set; }

/// <summary>
///
/// </summary>
public bool SkipVerification { get; set; }
}
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace PSRule.Tool.Models;
namespace PSRule.CommandLine.Models;

/// <summary>
/// A record of a module within the lock file.
Expand All @@ -10,4 +10,4 @@ namespace PSRule.Tool.Models;
/// <param name="Version">The version of the module.</param>
/// <param name="Installed">Is the version is installed.</param>
/// <param name="Locked">Is the module tracked.</param>
internal sealed record ModuleRecord(string Name, string Version, bool Installed, bool Locked);
public sealed record ModuleRecord(string Name, string Version, bool Installed, bool Locked);
20 changes: 20 additions & 0 deletions src/PSRule.CommandLine/Models/RestoreOptions.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.

namespace PSRule.CommandLine.Models;

/// <summary>
///
/// </summary>
public sealed class RestoreOptions
{
/// <summary>
///
/// </summary>
public string[]? Path { get; set; }

/// <summary>
///
/// </summary>
public bool Force { get; set; }
}
Loading

0 comments on commit 49d1193

Please sign in to comment.