├── global.json
├── src
├── Cupboard.Core
│ ├── IHasPackageName.cs
│ ├── IEnvironmentRefresher.cs
│ ├── IRebootDetector.cs
│ ├── ErrorOptions.cs
│ ├── IHasPackageState.cs
│ ├── IReportSubscriber.cs
│ ├── ISecurityPrincipal.cs
│ ├── PackageState.cs
│ ├── IO
│ │ ├── ChmodFormatting.cs
│ │ ├── ICupboardFileSystem.cs
│ │ ├── ChmodClass.cs
│ │ ├── ICupboardEnvironment.cs
│ │ ├── Permissions.cs
│ │ ├── SpecialMode.cs
│ │ ├── IProcessRunner.cs
│ │ ├── RegistryHive.cs
│ │ ├── RegistryValueKind.cs
│ │ ├── Obsolete
│ │ │ ├── RegistryKeyRoot.cs
│ │ │ └── RegistryKeyValueKind.cs
│ │ ├── IWindowsRegistry.cs
│ │ ├── ProcessRunnerResult.cs
│ │ ├── IWindowsRegistryKey.cs
│ │ ├── ChmodParser.cs
│ │ ├── ChmodFormatter.cs
│ │ ├── Chmod.cs
│ │ └── RegistryPath.cs
│ ├── RebootOptions.cs
│ ├── Manifest.cs
│ ├── PackageInstallerResult.cs
│ ├── IFactBuilder.cs
│ ├── Verbosity.cs
│ ├── PackageInstallerOperation.cs
│ ├── IResourceIdentity.cs
│ ├── ResourceState.cs
│ ├── ServiceModule.cs
│ ├── IFactProvider.cs
│ ├── Catalog.cs
│ ├── ICupboardLogger.cs
│ ├── IResourceBuilder.cs
│ ├── Extensions
│ │ ├── IEnumerableExtensions.cs
│ │ ├── FileSystemExtensions.cs
│ │ ├── ResourceStateExtensions.cs
│ │ ├── PathExtensions.cs
│ │ ├── ResourceExtensions.cs
│ │ ├── IWindowsRegistryExtensions.cs
│ │ └── ICupboardLoggerExtensions.cs
│ ├── IResourceProvider.cs
│ ├── IExecutionContext.cs
│ ├── Resource.cs
│ ├── ReportItem.cs
│ ├── CatalogContext.cs
│ ├── Cupboard.Core.csproj
│ ├── ManifestContext.cs
│ ├── LogLevel.cs
│ ├── Report.cs
│ ├── ResourceProvider.cs
│ ├── ResourceBuilder.cs
│ ├── FactCollection.cs
│ └── Fact.cs
├── Cupboard.Providers
│ ├── File
│ │ ├── FileState.cs
│ │ ├── File.cs
│ │ └── FileExtensions.cs
│ ├── Directory
│ │ ├── DirectoryState.cs
│ │ ├── Directory.cs
│ │ ├── DirectoryExtensions.cs
│ │ └── DirectoryProvider.cs
│ ├── PowerShell
│ │ ├── PowerShellFlavor.cs
│ │ ├── PowerShell.cs
│ │ └── PowerShellScriptExtensions.cs
│ ├── Exec
│ │ ├── Exec.cs
│ │ ├── ExecExtensions.cs
│ │ └── ExecProvider.cs
│ ├── VSCode
│ │ ├── VSCodeExtension.cs
│ │ ├── VSCodeExtensionExtensions.cs
│ │ └── VSCodeExtensionProvider.cs
│ ├── ArgumentFacts.cs
│ ├── Cupboard.Providers.csproj
│ ├── Download
│ │ ├── Download.cs
│ │ └── DownloadExtensions.cs
│ ├── EnvironmentFacts.cs
│ ├── ResourcesModule.cs
│ └── MachineFacts.cs
├── Cupboard.Providers.Windows
│ ├── Registry
│ │ ├── RegistryKeyState.cs
│ │ ├── RegistryValue.cs
│ │ ├── Obsolete
│ │ │ ├── RegistryKey.cs
│ │ │ └── RegistryKeyExtensions.cs
│ │ └── RegistryValueExtensions.cs
│ ├── Features
│ │ ├── WindowsFeatureState.cs
│ │ ├── WindowsFeature.cs
│ │ └── WindowsFeatureExtensions.cs
│ ├── WindowsFacts.cs
│ ├── Winget
│ │ ├── WingetPackage.cs
│ │ ├── WingetPackageExtensions.cs
│ │ └── WingetPackageProvider.cs
│ ├── WindowsResourceProvider.cs
│ ├── Chocolatey
│ │ ├── ChocolateyPackage.cs
│ │ ├── ChocolateyPackageExtensions.cs
│ │ └── ChocolateyPackageProvider.cs
│ ├── Cupboard.Providers.Windows.csproj
│ ├── WindowsModule.cs
│ └── WmiFacts.cs
├── Cupboard.Testing
│ ├── Fakes
│ │ ├── FakeEnvironmentRefresher.cs
│ │ ├── FakeSecurityPrincipal.cs
│ │ ├── FakeRebootDetector.cs
│ │ ├── FakeReportSubscriber.cs
│ │ ├── FakeFactBuilder.cs
│ │ ├── FakeWindowsRegistry.cs
│ │ ├── FakeCupboardFileSystem.cs
│ │ ├── FakeWindowsRegistryKey.cs
│ │ ├── FakeCupboardEnvironment.cs
│ │ ├── FakeLogger.cs
│ │ └── FakeProcessRunner.cs
│ ├── LambdaCatalog.cs
│ ├── Cupboard.Testing.csproj
│ └── Extensions
│ │ ├── ReportExtensions.cs
│ │ └── CupboardFixtureExtensions.cs
├── Cupboard
│ ├── WindowsCatalog.cs
│ ├── ResourceGraphEdge.cs
│ ├── Extensions
│ │ ├── IAnsiConsoleExtensions.cs
│ │ ├── RegistryValueKindExtensions.cs
│ │ ├── RegistryKeyValueKindExtensions.cs
│ │ └── ServiceCollectionExtensions.cs
│ ├── IO
│ │ ├── CupboardFileSystem.cs
│ │ ├── WindowsRegistry.cs
│ │ ├── CupboardEnvironment.cs
│ │ ├── WindowsRegistryKey.cs
│ │ └── ProcessRunner.cs
│ ├── SecurityPrincipal.cs
│ ├── Cli
│ │ ├── Infrastructure
│ │ │ ├── TypeResolver.cs
│ │ │ ├── FilePathConverter.cs
│ │ │ ├── DirectoryPathConverter.cs
│ │ │ ├── TypeRegistrar.cs
│ │ │ └── VerbosityConverter.cs
│ │ └── FactCommand.cs
│ ├── ExecutionPlanItem.cs
│ ├── ResourceIdentity.cs
│ ├── FactBuilder.cs
│ ├── IStatusUpdater.cs
│ ├── ExecutionPlan.cs
│ ├── Cupboard.csproj
│ ├── ResourceProviderRepository.cs
│ ├── ResourceComparer.cs
│ ├── ColorPalette.cs
│ ├── CupboardHost.cs
│ ├── EnvironmentRefresher.cs
│ ├── ResourceGraphBuilder.cs
│ ├── CupboardLogger.cs
│ ├── ResourceGraph.cs
│ ├── ExecutionPlanBuilder.cs
│ ├── RebootDetector.cs
│ ├── CupboardHostBuilder.cs
│ └── ResourceGraphWalker.cs
├── Directory.Build.targets
├── Sandbox
│ ├── Manifests
│ │ ├── WingetPackages.cs
│ │ ├── ChocolateyPackages.cs
│ │ ├── Chocolatey.cs
│ │ ├── VSCode.cs
│ │ ├── Rust.cs
│ │ └── WindowsSettings.cs
│ ├── Sandbox.csproj
│ ├── Program.cs
│ └── Facts
│ │ └── RustFactProvider.cs
├── Cupboard.Tests
│ ├── FakeProcessRunnerFixture.cs
│ ├── Properties
│ │ └── WindowsFact.cs
│ ├── Cupboard.Tests.csproj
│ ├── .editorconfig
│ ├── FactCollectionTests.cs
│ └── Unit
│ │ ├── IO
│ │ ├── RegistryKeyTests.cs
│ │ └── ChmodParserTests.cs
│ │ └── Providers
│ │ └── FileProviderTests.cs
├── stylecop.json
├── Directory.Build.props
└── .editorconfig
├── dotnet-tools.json
├── LICENSE.md
├── .github
└── workflows
│ ├── ci.yaml
│ └── publish.yaml
├── .gitignore
└── CODE_OF_CONDUCT.md
/global.json:
--------------------------------------------------------------------------------
1 | {
2 | "projects": [ "src" ],
3 | "sdk": {
4 | "version": "5.0.301",
5 | "rollForward": "latestPatch"
6 | }
7 | }
--------------------------------------------------------------------------------
/src/Cupboard.Core/IHasPackageName.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IHasPackageName
4 | {
5 | string Package { get; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/File/FileState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum FileState
4 | {
5 | Present,
6 | Absent,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IEnvironmentRefresher.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IEnvironmentRefresher
4 | {
5 | void Refresh();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IRebootDetector.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IRebootDetector
4 | {
5 | bool HasPendingReboot();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ErrorOptions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum ErrorOptions
4 | {
5 | IgnoreErrors = 0,
6 | Abort = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IHasPackageState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IHasPackageState
4 | {
5 | PackageState Ensure { get; }
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IReportSubscriber.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IReportSubscriber
4 | {
5 | void Notify(Report report);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ISecurityPrincipal.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface ISecurityPrincipal
4 | {
5 | bool IsAdministrator();
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/PackageState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum PackageState
4 | {
5 | Installed = 1,
6 | Uninstalled = 2,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/ChmodFormatting.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum ChmodFormatting
4 | {
5 | Numeric = 0,
6 | Symbolic = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/ICupboardFileSystem.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public interface ICupboardFileSystem : IFileSystem
6 | {
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/RebootOptions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum RebootOptions
4 | {
5 | IgnorePendingReboot = 0,
6 | Reboot = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Manifest.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public abstract class Manifest
4 | {
5 | public abstract void Execute(ManifestContext context);
6 | }
7 | }
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Directory/DirectoryState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum DirectoryState
4 | {
5 | Present = 0,
6 | Absent = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/PowerShell/PowerShellFlavor.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum PowerShellFlavor
4 | {
5 | PowerShell,
6 | PowerShellCore,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/ChmodClass.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum ChmodClass
4 | {
5 | Owner = 0,
6 | Group = 1,
7 | Other = 2,
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Registry/RegistryKeyState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum RegistryKeyState
4 | {
5 | Exist = 0,
6 | DoNotExist = 1,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Features/WindowsFeatureState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum WindowsFeatureState
4 | {
5 | Enabled = 0,
6 | Disabled,
7 | }
8 | }
9 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/PackageInstallerResult.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum PackageInstallerResult
4 | {
5 | Exists = 0,
6 | Missing = 1,
7 | Error = 2,
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/dotnet-tools.json:
--------------------------------------------------------------------------------
1 | {
2 | "version": 1,
3 | "isRoot": true,
4 | "tools": {
5 | "cake.tool": {
6 | "version": "1.1.0",
7 | "commands": [
8 | "dotnet-cake"
9 | ]
10 | }
11 | }
12 | }
--------------------------------------------------------------------------------
/src/Cupboard.Core/IFactBuilder.cs:
--------------------------------------------------------------------------------
1 | using Spectre.Console.Cli;
2 |
3 | namespace Cupboard
4 | {
5 | public interface IFactBuilder
6 | {
7 | FactCollection Build(IRemainingArguments args);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/ICupboardEnvironment.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public interface ICupboardEnvironment : IEnvironment
6 | {
7 | FilePath GetTempFilePath();
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Verbosity.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum Verbosity
4 | {
5 | Quiet = 0,
6 | Minimal,
7 | Normal,
8 | Verbose,
9 | Diagnostic,
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/PackageInstallerOperation.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum PackageInstallerOperation
4 | {
5 | RetriveState = 0,
6 | Install = 1,
7 | Uninstall = 2,
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IResourceIdentity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public interface IResourceIdentity
6 | {
7 | Type ResourceType { get; }
8 |
9 | string Name { get; }
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ResourceState.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum ResourceState
4 | {
5 | Unknown = 0,
6 | Changed,
7 | Unchanged,
8 | Executed,
9 | Skipped,
10 | Error,
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeEnvironmentRefresher.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Testing
2 | {
3 | public sealed class FakeEnvironmentRefresher : IEnvironmentRefresher
4 | {
5 | public void Refresh()
6 | {
7 | }
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ServiceModule.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 |
3 | namespace Cupboard
4 | {
5 | public abstract class ServiceModule
6 | {
7 | public abstract void Configure(IServiceCollection services);
8 | }
9 | }
10 |
--------------------------------------------------------------------------------
/src/Cupboard/WindowsCatalog.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public abstract class WindowsCatalog : Catalog
4 | {
5 | public override bool CanRun(FactCollection facts)
6 | {
7 | return facts.IsWindows();
8 | }
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IFactProvider.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Spectre.Console.Cli;
3 |
4 | namespace Cupboard
5 | {
6 | public interface IFactProvider
7 | {
8 | IEnumerable<(string Name, object Value)> GetFacts(IRemainingArguments args);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/Permissions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | [Flags]
6 | public enum Permissions
7 | {
8 | None = 0,
9 | Execute = 1,
10 | Write = 2,
11 | Read = 4,
12 | All = Read | Write | Execute,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Directory.Build.targets:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | preview
5 | normal
6 |
7 |
8 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Catalog.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public abstract class Catalog
4 | {
5 | public virtual bool CanRun(FactCollection facts)
6 | {
7 | return true;
8 | }
9 |
10 | public abstract void Execute(CatalogContext context);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/SpecialMode.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | [Flags]
6 | public enum SpecialMode
7 | {
8 | None = 0,
9 | Sticky = 1,
10 | Setgid = 1 << 1,
11 | Setuid = 1 << 2,
12 | All = Sticky | Setgid | Setuid,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/IProcessRunner.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace Cupboard
5 | {
6 | public interface IProcessRunner
7 | {
8 | Task Run(string file, string arguments, Func? filter = null, bool supressOutput = false);
9 | }
10 | }
11 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/RegistryHive.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum RegistryHive
4 | {
5 | Unknown = 0,
6 | ClassesRoot = 1,
7 | CurrentUser = 2,
8 | LocalMachine = 3,
9 | Users = 4,
10 | CurrentConfig = 5,
11 | PerformanceData = 6,
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/RegistryValueKind.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum RegistryValueKind
4 | {
5 | None = -1,
6 | Unknown = 0,
7 | String = 1,
8 | ExpandString = 2,
9 | Binary = 3,
10 | DWord = 4,
11 | MultiString = 7,
12 | QWord = 11,
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeSecurityPrincipal.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Testing
2 | {
3 | public sealed class FakeSecurityPrincipal : ISecurityPrincipal
4 | {
5 | public bool IsAdmin { get; set; }
6 |
7 | public bool IsAdministrator()
8 | {
9 | return IsAdmin;
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeRebootDetector.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Testing
2 | {
3 | public sealed class FakeRebootDetector : IRebootDetector
4 | {
5 | public bool PendingReboot { get; set; }
6 |
7 | public bool HasPendingReboot()
8 | {
9 | return PendingReboot;
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeReportSubscriber.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Testing
2 | {
3 | internal sealed class FakeReportSubscriber : IReportSubscriber
4 | {
5 | public Report? Report { get; set; }
6 |
7 | public void Notify(Report report)
8 | {
9 | Report = report;
10 | }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ICupboardLogger.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface ICupboardLogger
4 | {
5 | Verbosity Verbosity { get; }
6 |
7 | void SetVerbosity(Verbosity verbosity);
8 | void Log(Verbosity verbosity, LogLevel level, string text);
9 | void Log(Verbosity verbosity, LogLevel level, string title, string text);
10 | }
11 | }
12 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/Obsolete/RegistryKeyRoot.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | [Obsolete("Please use RegistryRoot instead")]
6 | public enum RegistryKeyRoot
7 | {
8 | Unknown = 0,
9 | ClassesRoot = 1,
10 | CurrentUser = 2,
11 | LocalMachine = 3,
12 | Users = 4,
13 | CurrentConfig = 5,
14 | PerformanceData = 6,
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Features/WindowsFeature.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public sealed class WindowsFeature : Resource
4 | {
5 | public string? FeatureName { get; set; }
6 | public WindowsFeatureState Ensure { get; set; } = WindowsFeatureState.Enabled;
7 |
8 | public WindowsFeature(string name)
9 | : base(name)
10 | {
11 | }
12 | }
13 | }
14 |
--------------------------------------------------------------------------------
/src/Cupboard/ResourceGraphEdge.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Internal
2 | {
3 | internal sealed class ResourceGraphEdge
4 | {
5 | public IResourceIdentity From { get; }
6 | public IResourceIdentity To { get; }
7 |
8 | public ResourceGraphEdge(IResourceIdentity from, IResourceIdentity to)
9 | {
10 | From = from;
11 | To = to;
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IResourceBuilder.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public interface IResourceBuilder
6 | where TResource : Resource
7 | {
8 | IResourceBuilder Before(string name);
9 | IResourceBuilder After(string name);
10 | IResourceBuilder Configure(Action action);
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/Obsolete/RegistryKeyValueKind.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | [Obsolete("Please use RegistryValueKind instead")]
6 | public enum RegistryKeyValueKind
7 | {
8 | None = -1,
9 | Unknown = 0,
10 | String = 1,
11 | ExpandString = 2,
12 | Binary = 3,
13 | DWord = 4,
14 | MultiString = 7,
15 | QWord = 11,
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Extensions/IEnumerableExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Cupboard
5 | {
6 | public static class IEnumerableExtensions
7 | {
8 | public static IReadOnlyList ToReadOnlyList(this IEnumerable source)
9 | {
10 | return source as IReadOnlyList
11 | ?? new List(source ?? Array.Empty());
12 | }
13 | }
14 | }
15 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/IWindowsRegistry.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public interface IWindowsRegistry
4 | {
5 | IWindowsRegistryKey ClassesRoot { get; }
6 | IWindowsRegistryKey CurrentConfig { get; }
7 | IWindowsRegistryKey CurrentUser { get; }
8 | IWindowsRegistryKey LocalMachine { get; }
9 | IWindowsRegistryKey PerformanceData { get; }
10 | IWindowsRegistryKey Users { get; }
11 | }
12 | }
13 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IResourceProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Threading.Tasks;
3 |
4 | namespace Cupboard
5 | {
6 | public interface IResourceProvider
7 | {
8 | Type ResourceType { get; }
9 |
10 | Resource Create(string name);
11 |
12 | bool RequireAdministrator(FactCollection facts);
13 | bool CanRun(FactCollection facts);
14 | Task RunAsync(IExecutionContext context, Resource resource);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Sandbox/Manifests/WingetPackages.cs:
--------------------------------------------------------------------------------
1 | using Cupboard;
2 |
3 | namespace Sandbox
4 | {
5 | public sealed class WingetPackages : Manifest
6 | {
7 | public override void Execute(ManifestContext context)
8 | {
9 | foreach (var package in new[] { "GitHub.cli" })
10 | {
11 | context.Resource(package)
12 | .Ensure(PackageState.Installed);
13 | }
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeFactBuilder.cs:
--------------------------------------------------------------------------------
1 | using Spectre.Console.Cli;
2 |
3 | namespace Cupboard.Testing
4 | {
5 | public sealed class FakeFactBuilder : IFactBuilder
6 | {
7 | public FactCollection Facts { get; set; }
8 |
9 | public FakeFactBuilder()
10 | {
11 | Facts = new FactCollection();
12 | }
13 |
14 | public FactCollection Build(IRemainingArguments args)
15 | {
16 | return Facts;
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Cupboard/Extensions/IAnsiConsoleExtensions.cs:
--------------------------------------------------------------------------------
1 | using Spectre.Console;
2 |
3 | namespace Cupboard.Internal
4 | {
5 | internal static class IAnsiConsoleExtensions
6 | {
7 | public static bool Confirm(this IAnsiConsole console, string markup, bool defaultValue = true)
8 | {
9 | return new ConfirmationPrompt(markup)
10 | {
11 | DefaultValue = defaultValue,
12 | }
13 | .Show(console);
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Directory/Directory.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class Directory : Resource
6 | {
7 | public DirectoryPath Path { get; set; }
8 | public DirectoryState Ensure { get; set; } = DirectoryState.Present;
9 | public Chmod? Permissions { get; set; }
10 |
11 | public Directory(string name)
12 | : base(name)
13 | {
14 | Path = new DirectoryPath(name);
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Cupboard/IO/CupboardFileSystem.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard.Internal
4 | {
5 | internal sealed class CupboardFileSystem : ICupboardFileSystem
6 | {
7 | private readonly IFileSystem _fileSystem;
8 |
9 | public IFileProvider File => _fileSystem.File;
10 | public IDirectoryProvider Directory => _fileSystem.Directory;
11 |
12 | public CupboardFileSystem()
13 | {
14 | _fileSystem = new FileSystem();
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Exec/Exec.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Spectre.IO;
3 |
4 | namespace Cupboard
5 | {
6 | public sealed class Exec : Resource
7 | {
8 | public FilePath Path { get; set; }
9 | public string? Args { get; set; }
10 | public int[]? ValidExitCodes { get; set; }
11 |
12 | public Exec(string name)
13 | : base(name)
14 | {
15 | Path = new FilePath(name ?? throw new ArgumentNullException(nameof(name)));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/PowerShell/PowerShell.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class PowerShell : Resource
6 | {
7 | public FilePath? Script { get; set; }
8 | public string? Command { get; set; }
9 | public string? Unless { get; set; }
10 | public PowerShellFlavor Flavor { get; set; } = PowerShellFlavor.PowerShell;
11 |
12 | public PowerShell(string name)
13 | : base(name)
14 | {
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Sandbox/Sandbox.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | Exe
5 | net5.0
6 | false
7 | enable
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/VSCode/VSCodeExtension.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class VSCodeExtension : Resource, IHasPackageName, IHasPackageState
6 | {
7 | public string Package { get; set; }
8 | public PackageState Ensure { get; set; } = PackageState.Installed;
9 |
10 | public VSCodeExtension(string name)
11 | : base(name)
12 | {
13 | Package = name ?? throw new ArgumentNullException(nameof(name));
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/File/File.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class File : Resource
6 | {
7 | public FilePath? Destination { get; set; }
8 | public FilePath? Source { get; set; }
9 | public FileState Ensure { get; set; } = FileState.Present;
10 | public bool SymbolicLink { get; set; }
11 | public Chmod? Permissions { get; set; }
12 |
13 | public File(string name)
14 | : base(name)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/ArgumentFacts.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using System.Linq;
3 | using Spectre.Console.Cli;
4 |
5 | namespace Cupboard
6 | {
7 | internal sealed class ArgumentFacts : IFactProvider
8 | {
9 | public IEnumerable<(string Name, object Value)> GetFacts(IRemainingArguments args)
10 | {
11 | foreach (var argument in args.Parsed)
12 | {
13 | yield return ("arg." + argument.Key, argument.Last() ?? string.Empty);
14 | }
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/LambdaCatalog.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard.Testing
4 | {
5 | public sealed class LambdaCatalog : Catalog
6 | {
7 | private readonly Action _action;
8 |
9 | public LambdaCatalog(Action action)
10 | {
11 | _action = action ?? throw new ArgumentNullException(nameof(action));
12 | }
13 |
14 | public override void Execute(CatalogContext context)
15 | {
16 | _action(context);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/WindowsFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Spectre.Console.Cli;
4 |
5 | namespace Cupboard
6 | {
7 | internal sealed class WindowsFacts : IFactProvider
8 | {
9 | public IEnumerable<(string Name, object Value)> GetFacts(IRemainingArguments args)
10 | {
11 | var isSandboxUser = Environment.UserName.Equals("WDAGUtilityAccount", StringComparison.OrdinalIgnoreCase);
12 | yield return ("windows.sandbox", isSandboxUser);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Sandbox/Manifests/ChocolateyPackages.cs:
--------------------------------------------------------------------------------
1 | using Cupboard;
2 |
3 | namespace Sandbox
4 | {
5 | public sealed class ChocolateyPackages : Manifest
6 | {
7 | public override void Execute(ManifestContext context)
8 | {
9 | foreach (var package in new[] { "screentogif", "repoz" })
10 | {
11 | context.Resource(package)
12 | .Ensure(PackageState.Installed)
13 | .After("Install Chocolatey");
14 | }
15 | }
16 | }
17 | }
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Cupboard.Providers.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | 9.0
6 | enable
7 | true
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/ProcessRunnerResult.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public sealed class ProcessRunnerResult
4 | {
5 | public int ExitCode { get; }
6 | public string StandardOut { get; }
7 | public string StandardError { get; }
8 |
9 | public ProcessRunnerResult(int exitCode, string? standardOut = null, string? standardError = null)
10 | {
11 | ExitCode = exitCode;
12 | StandardOut = standardOut ?? string.Empty;
13 | StandardError = standardError ?? string.Empty;
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Registry/RegistryValue.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public sealed class RegistryValue : Resource
4 | {
5 | public RegistryPath? Path { get; set; }
6 | public string? Value { get; set; }
7 | public object? Data { get; set; }
8 | public RegistryValueKind ValueKind { get; set; } = RegistryValueKind.Unknown;
9 | public RegistryKeyState State { get; set; } = RegistryKeyState.Exist;
10 |
11 | public RegistryValue(string name)
12 | : base(name)
13 | {
14 | }
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Download/Download.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Spectre.IO;
3 |
4 | namespace Cupboard
5 | {
6 | public sealed class Download : Resource
7 | {
8 | public Uri? Url { get; set; }
9 | public Chmod? Permissions { get; set; }
10 | public Path? Destination { get; set; }
11 |
12 | public Download(string name)
13 | : base(name)
14 | {
15 | if (Uri.TryCreate(name, UriKind.Absolute, out var result))
16 | {
17 | Url = result;
18 | }
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Extensions/FileSystemExtensions.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public static class FileSystemExtensions
6 | {
7 | public static bool CreateSymbolicLinkSafe(this IFileProvider fileProvider, FilePath source, FilePath destination)
8 | {
9 | try
10 | {
11 | fileProvider.CreateSymbolicLink(source, destination);
12 | return true;
13 | }
14 | catch
15 | {
16 | return false;
17 | }
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IExecutionContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public interface IExecutionContext
6 | {
7 | FactCollection Facts { get; }
8 | bool DryRun { get; }
9 | }
10 |
11 | public sealed class ExecutionContext : IExecutionContext
12 | {
13 | public FactCollection Facts { get; }
14 | public bool DryRun { get; init; } = false;
15 |
16 | public ExecutionContext(FactCollection facts)
17 | {
18 | Facts = facts ?? throw new ArgumentNullException(nameof(facts));
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Cupboard/SecurityPrincipal.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using System.Security.Principal;
3 | using Mono.Unix.Native;
4 |
5 | namespace Cupboard.Internal
6 | {
7 | internal sealed class SecurityPrincipal : ISecurityPrincipal
8 | {
9 | public bool IsAdministrator()
10 | {
11 | return RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ?
12 | new WindowsPrincipal(WindowsIdentity.GetCurrent())
13 | .IsInRole(WindowsBuiltInRole.Administrator) :
14 | Syscall.geteuid() == 0;
15 | }
16 | }
17 | }
18 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Winget/WingetPackage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class WingetPackage : Resource, IHasPackageName, IHasPackageState
6 | {
7 | public string Package { get; set; }
8 | public PackageState Ensure { get; set; }
9 | public bool Force { get; set; }
10 | public string? PackageVersion { get; set; }
11 |
12 | public WingetPackage(string name)
13 | : base(name)
14 | {
15 | Package = name ?? throw new ArgumentNullException(nameof(name));
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Sandbox/Program.cs:
--------------------------------------------------------------------------------
1 | using Cupboard;
2 |
3 | namespace Sandbox
4 | {
5 | public static class Program
6 | {
7 | public static int Main(string[] args)
8 | {
9 | return CupboardHost.CreateBuilder()
10 | .AddCatalog()
11 | .Run(args);
12 | }
13 | }
14 |
15 | public sealed class SandboxCatalog : WindowsCatalog
16 | {
17 | public override void Execute(CatalogContext context)
18 | {
19 | context.UseManifest();
20 | context.UseManifest();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Resource.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public abstract class Resource : IResourceIdentity
6 | {
7 | public Type ResourceType => GetType();
8 |
9 | public string Name { get; }
10 | public bool RequireAdministrator { get; set; }
11 |
12 | public ErrorOptions Error { get; set; } = ErrorOptions.Abort;
13 | public RebootOptions Reboot { get; set; } = RebootOptions.Reboot;
14 |
15 | protected Resource(string name)
16 | {
17 | Name = name ?? throw new ArgumentNullException(nameof(name));
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Registry/Obsolete/RegistryKey.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | [Obsolete("Please use the RegistryValue resource")]
6 | public sealed class RegistryKey : Resource
7 | {
8 | public RegistryKeyPath? Path { get; set; }
9 | public object? Value { get; set; }
10 | public RegistryKeyValueKind ValueKind { get; set; } = RegistryKeyValueKind.Unknown;
11 | public RegistryKeyState State { get; set; } = RegistryKeyState.Exist;
12 |
13 | public RegistryKey(string name)
14 | : base(name)
15 | {
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/VSCode/VSCodeExtensionExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public static class VSCodeExtensionExtensions
4 | {
5 | public static IResourceBuilder Ensure(this IResourceBuilder builder, PackageState state)
6 | {
7 | return builder.Configure(file => file.Ensure = state);
8 | }
9 |
10 | public static IResourceBuilder Package(this IResourceBuilder builder, string package)
11 | {
12 | return builder.Configure(pkg => pkg.Package = package);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Cupboard.Tests/FakeProcessRunnerFixture.cs:
--------------------------------------------------------------------------------
1 | using NSubstitute;
2 |
3 | namespace Cupboard.Tests.Resources
4 | {
5 | public sealed class FakeProcessRunnerFixture
6 | {
7 | public IProcessRunner Runner { get; }
8 |
9 | public FakeProcessRunnerFixture()
10 | {
11 | Runner = Substitute.For();
12 | }
13 |
14 | public void Register(string file, string arguments, ProcessRunnerResult result, params ProcessRunnerResult[] results)
15 | {
16 | Runner.Run(Arg.Is(file), Arg.Is(arguments)).Returns(result, results);
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Cupboard.Tests/Properties/WindowsFact.cs:
--------------------------------------------------------------------------------
1 | using System.Runtime.InteropServices;
2 | using Xunit;
3 |
4 | namespace Cupboard.Tests.Unit
5 | {
6 | public sealed class WindowsFact : FactAttribute
7 | {
8 | private static readonly bool _isWindows;
9 |
10 | static WindowsFact()
11 | {
12 | _isWindows = RuntimeInformation.IsOSPlatform(OSPlatform.Windows);
13 | }
14 |
15 | public WindowsFact(string reason = null)
16 | {
17 | if (!_isWindows)
18 | {
19 | Skip = reason ?? "Windows test.";
20 | }
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ReportItem.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public sealed class ReportItem
4 | {
5 | public Resource Resource { get; }
6 | public IResourceProvider Provider { get; }
7 | public ResourceState State { get; }
8 | public bool RequireAdministrator { get; }
9 |
10 | public ReportItem(IResourceProvider provider, Resource resource, ResourceState state, bool requireAdministrator)
11 | {
12 | Provider = provider;
13 | Resource = resource;
14 | State = state;
15 | RequireAdministrator = requireAdministrator;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Features/WindowsFeatureExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public static class WindowsFeatureExtensions
4 | {
5 | public static IResourceBuilder Ensure(this IResourceBuilder builder, WindowsFeatureState state)
6 | {
7 | return builder.Configure(file => file.Ensure = state);
8 | }
9 |
10 | public static IResourceBuilder FeatureName(this IResourceBuilder builder, string name)
11 | {
12 | return builder.Configure(file => file.FeatureName = name);
13 | }
14 | }
15 | }
16 |
--------------------------------------------------------------------------------
/src/Cupboard/Cli/Infrastructure/TypeResolver.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Spectre.Console.Cli;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | internal sealed class TypeResolver : ITypeResolver
7 | {
8 | private readonly IServiceProvider _provider;
9 |
10 | public TypeResolver(IServiceProvider provider)
11 | {
12 | _provider = provider;
13 | }
14 |
15 | public object? Resolve(Type? type)
16 | {
17 | if (type == null)
18 | {
19 | return null;
20 | }
21 |
22 | return _provider.GetService(type);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/WindowsResourceProvider.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public abstract class WindowsResourceProvider : ResourceProvider
4 | where TResource : Resource
5 | {
6 | public override bool CanRun(FactCollection facts)
7 | {
8 | return facts.IsWindows();
9 | }
10 | }
11 |
12 | public abstract class AsyncWindowsResourceProvider : AsyncResourceProvider
13 | where TResource : Resource
14 | {
15 | public override bool CanRun(FactCollection facts)
16 | {
17 | return facts.IsWindows();
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Chocolatey/ChocolateyPackage.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class ChocolateyPackage : Resource, IHasPackageState, IHasPackageName
6 | {
7 | public string Package { get; set; }
8 | public PackageState Ensure { get; set; }
9 | public bool PreRelease { get; set; }
10 | public bool IgnoreChecksum { get; set; }
11 | public string? PackageParameters { get; set; }
12 |
13 | public ChocolateyPackage(string name)
14 | : base(name)
15 | {
16 | Package = name ?? throw new ArgumentNullException(nameof(name));
17 | }
18 | }
19 | }
20 |
--------------------------------------------------------------------------------
/src/Cupboard/ExecutionPlanItem.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard.Internal
4 | {
5 | internal sealed class ExecutionPlanItem
6 | {
7 | public IResourceProvider Provider { get; }
8 | public Resource Resource { get; }
9 | public bool RequireAdministrator { get; }
10 |
11 | public ExecutionPlanItem(IResourceProvider provider, Resource resource, bool requireAdministrator)
12 | {
13 | Provider = provider ?? throw new ArgumentNullException(nameof(provider));
14 | Resource = resource ?? throw new ArgumentNullException(nameof(resource));
15 | RequireAdministrator = requireAdministrator;
16 | }
17 | }
18 | }
19 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Cupboard.Testing.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | 9.0
6 | enable
7 | true
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/IO/IWindowsRegistryKey.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public interface IWindowsRegistryKey
6 | {
7 | IWindowsRegistryKey? OpenSubKey(string name, bool writable);
8 | IWindowsRegistryKey? CreateSubKey(string name, bool writable);
9 |
10 | int GetValueCount();
11 |
12 | bool ValueExists(string name);
13 | object? GetValue(string name);
14 | void DeleteValue(string name);
15 |
16 | [Obsolete("Please use SetValue overload accepting a RegistryValueKind instead")]
17 | void SetValue(string name, object value, RegistryKeyValueKind kind);
18 |
19 | void SetValue(string name, object value, RegistryValueKind kind);
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Extensions/ResourceStateExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard
4 | {
5 | public static class ResourceStateExtensions
6 | {
7 | public static bool IsError(this ResourceState state)
8 | {
9 | return state switch
10 | {
11 | ResourceState.Unknown => true,
12 | ResourceState.Changed => false,
13 | ResourceState.Unchanged => false,
14 | ResourceState.Error => true,
15 | ResourceState.Skipped => false,
16 | ResourceState.Executed => false,
17 | _ => throw new InvalidOperationException($"Unknown resource state '{state}'"),
18 | };
19 | }
20 | }
21 | }
22 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Extensions/ReportExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Linq;
3 |
4 | namespace Cupboard.Testing
5 | {
6 | public static class ReportExtensions
7 | {
8 | public static ResourceState GetState(this Report report, string name)
9 | where TResource : Resource
10 | {
11 | if (report == null)
12 | {
13 | return ResourceState.Unknown;
14 | }
15 |
16 | var item = report.Items.SingleOrDefault(
17 | x => x.Resource.GetType() == typeof(TResource)
18 | && x.Resource.Name.Equals(name, StringComparison.OrdinalIgnoreCase));
19 |
20 | return item?.State ?? ResourceState.Unknown;
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Cupboard/Cli/Infrastructure/FilePathConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Globalization;
4 | using Spectre.IO;
5 |
6 | namespace Cupboard.Internal
7 | {
8 | ///
9 | /// A type converter for .
10 | ///
11 | internal sealed class FilePathConverter : TypeConverter
12 | {
13 | ///
14 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
15 | {
16 | if (value is string stringValue)
17 | {
18 | return new FilePath(stringValue);
19 | }
20 |
21 | throw new NotSupportedException("Can't convert value to file path.");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Extensions/PathExtensions.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Runtime.InteropServices;
3 | using Mono.Unix;
4 | using Spectre.IO;
5 |
6 | namespace Cupboard
7 | {
8 | public static class PathExtensions
9 | {
10 | public static void SetPermissions(this Path path, Chmod chmod)
11 | {
12 | if (path is null)
13 | {
14 | throw new ArgumentNullException(nameof(path));
15 | }
16 |
17 | if (RuntimeInformation.IsOSPlatform(OSPlatform.Windows))
18 | {
19 | return;
20 | }
21 |
22 | var info = UnixFileSystemInfo.GetFileSystemEntry(path.FullPath);
23 | info.FileAccessPermissions = chmod.ToFileAccessPermissions();
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Cupboard/ResourceIdentity.cs:
--------------------------------------------------------------------------------
1 | using System;
2 |
3 | namespace Cupboard.Internal
4 | {
5 | internal sealed class ResourceIdentity : IResourceIdentity
6 | {
7 | public Type ResourceType { get; }
8 | public string Name { get; }
9 |
10 | public ResourceIdentity(Type resourceType, string name)
11 | {
12 | ResourceType = resourceType;
13 | Name = name;
14 | }
15 |
16 | public ResourceIdentity(Resource resource)
17 | {
18 | ResourceType = resource.ResourceType;
19 | Name = resource.Name;
20 | }
21 |
22 | public ResourceIdentity(Tuple tuple)
23 | {
24 | ResourceType = tuple.Item1;
25 | Name = tuple.Item2;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Cupboard/Cli/Infrastructure/DirectoryPathConverter.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.ComponentModel;
3 | using System.Globalization;
4 | using Spectre.IO;
5 |
6 | namespace Cupboard.Internal
7 | {
8 | ///
9 | /// A type converter for .
10 | ///
11 | internal sealed class DirectoryPathConverter : TypeConverter
12 | {
13 | ///
14 | public override object ConvertFrom(ITypeDescriptorContext context, CultureInfo culture, object value)
15 | {
16 | if (value is string stringValue)
17 | {
18 | return new DirectoryPath(stringValue);
19 | }
20 |
21 | throw new NotSupportedException("Can't convert value to file path.");
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/CatalogContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Cupboard
5 | {
6 | public sealed class CatalogContext
7 | {
8 | private readonly HashSet _manifests;
9 |
10 | public FactCollection Facts { get; }
11 |
12 | public CatalogContext(FactCollection facts)
13 | {
14 | Facts = facts ?? throw new ArgumentNullException(nameof(facts));
15 | _manifests = new HashSet();
16 | }
17 |
18 | public void UseManifest()
19 | where TManifest : Manifest
20 | {
21 | _manifests.Add(typeof(TManifest));
22 | }
23 |
24 | public IEnumerable GetManifests()
25 | {
26 | return _manifests;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/EnvironmentFacts.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Spectre.Console.Cli;
4 |
5 | namespace Cupboard
6 | {
7 | internal sealed class EnvironmentFacts : IFactProvider
8 | {
9 | private readonly ICupboardEnvironment _environment;
10 |
11 | public EnvironmentFacts(ICupboardEnvironment environment)
12 | {
13 | _environment = environment ?? throw new ArgumentNullException(nameof(environment));
14 | }
15 |
16 | public IEnumerable<(string Name, object Value)> GetFacts(IRemainingArguments args)
17 | {
18 | foreach (var (key, value) in _environment.GetEnvironmentVariables())
19 | {
20 | yield return ($"env.{key}", value ?? string.Empty);
21 | }
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/stylecop.json:
--------------------------------------------------------------------------------
1 | {
2 | "$schema": "https://raw.githubusercontent.com/DotNetAnalyzers/StyleCopAnalyzers/master/StyleCop.Analyzers/StyleCop.Analyzers/Settings/stylecop.schema.json",
3 | "settings": {
4 | "documentationRules": {
5 | "documentExposedElements": true,
6 | "documentInternalElements": false,
7 | "documentPrivateElements": false,
8 | "documentPrivateFields": false
9 | },
10 | "layoutRules": {
11 | "newlineAtEndOfFile": "allow",
12 | "allowConsecutiveUsings": true
13 | },
14 | "orderingRules": {
15 | "usingDirectivesPlacement": "outsideNamespace",
16 | "systemUsingDirectivesFirst": true,
17 | "elementOrder": [
18 | "kind",
19 | "accessibility",
20 | "constant",
21 | "static",
22 | "readonly"
23 | ]
24 | }
25 | }
26 | }
--------------------------------------------------------------------------------
/src/Cupboard.Core/Cupboard.Core.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | 9.0
6 | enable
7 | true
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Cupboard.Providers.Windows.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | 9.0
6 | enable
7 | true
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Exec/ExecExtensions.cs:
--------------------------------------------------------------------------------
1 | using Spectre.IO;
2 |
3 | namespace Cupboard
4 | {
5 | public static class ExecExtensions
6 | {
7 | public static IResourceBuilder Path(this IResourceBuilder builder, FilePath file)
8 | {
9 | builder.Configure(res => res.Path = file);
10 | return builder;
11 | }
12 |
13 | public static IResourceBuilder Arguments(this IResourceBuilder builder, string args)
14 | {
15 | builder.Configure(res => res.Args = args);
16 | return builder;
17 | }
18 |
19 | public static IResourceBuilder ValidExitCodes(this IResourceBuilder builder, params int[] exitCodes)
20 | {
21 | builder.Configure(res => res.ValidExitCodes = exitCodes);
22 | return builder;
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/ManifestContext.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Cupboard
5 | {
6 | public sealed class ManifestContext
7 | {
8 | public FactCollection Facts { get; }
9 | public List Builders { get; }
10 |
11 | public ManifestContext(FactCollection facts)
12 | {
13 | Facts = facts ?? throw new ArgumentNullException(nameof(facts));
14 | Builders = new List();
15 | }
16 |
17 | public IResourceBuilder Resource(string name)
18 | where TResource : Resource
19 | {
20 | var builder = new ResourceBuilder(name);
21 |
22 | // Store a reference to the configuration.
23 | Builders.Add(builder);
24 |
25 | return builder;
26 | }
27 | }
28 | }
29 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/Directory/DirectoryExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public static class DirectoryExtensions
4 | {
5 | public static IResourceBuilder Ensure(this IResourceBuilder builder, DirectoryState state)
6 | {
7 | return builder.Configure(directory => directory.Ensure = state);
8 | }
9 |
10 | public static IResourceBuilder Permissions(this IResourceBuilder builder, string chmod)
11 | {
12 | return builder.Configure(directory => directory.Permissions = ChmodParser.Parse(chmod));
13 | }
14 |
15 | public static IResourceBuilder Permissions(this IResourceBuilder builder, Chmod permissions)
16 | {
17 | return builder.Configure(directory => directory.Permissions = permissions);
18 | }
19 | }
20 | }
21 |
--------------------------------------------------------------------------------
/src/Cupboard/FactBuilder.cs:
--------------------------------------------------------------------------------
1 | using System.Collections.Generic;
2 | using Spectre.Console.Cli;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | internal sealed class FactBuilder : IFactBuilder
7 | {
8 | private readonly IReadOnlyList _providers;
9 |
10 | public FactBuilder(IEnumerable providers)
11 | {
12 | _providers = providers.ToReadOnlyList();
13 | }
14 |
15 | public FactCollection Build(IRemainingArguments args)
16 | {
17 | var facts = new FactCollection();
18 | foreach (var provider in _providers)
19 | {
20 | foreach (var (name, value) in provider.GetFacts(args))
21 | {
22 | facts.Add(name, value ?? string.Empty);
23 | }
24 | }
25 |
26 | return facts;
27 | }
28 | }
29 | }
30 |
--------------------------------------------------------------------------------
/src/Cupboard/IStatusUpdater.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Spectre.Console;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | internal interface IStatusUpdater
7 | {
8 | void Update(string markup);
9 | }
10 |
11 | internal sealed class StatusUpdater : IStatusUpdater
12 | {
13 | private readonly StatusContext _context;
14 |
15 | public StatusUpdater(StatusContext context)
16 | {
17 | _context = context ?? throw new ArgumentNullException(nameof(context));
18 | }
19 |
20 | public void Update(string markup)
21 | {
22 | if (!string.IsNullOrWhiteSpace(markup))
23 | {
24 | _context.Status = markup;
25 | }
26 | }
27 | }
28 |
29 | internal sealed class DummyUpdater : IStatusUpdater
30 | {
31 | public void Update(string markup)
32 | {
33 | }
34 | }
35 | }
36 |
--------------------------------------------------------------------------------
/src/Cupboard/IO/WindowsRegistry.cs:
--------------------------------------------------------------------------------
1 | using System.Diagnostics.CodeAnalysis;
2 | using Win32Registry = Microsoft.Win32.Registry;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | [SuppressMessage("Interoperability", "CA1416:Validate platform compatibility")]
7 | internal sealed class WindowsRegistry : IWindowsRegistry
8 | {
9 | public IWindowsRegistryKey ClassesRoot => new WindowsRegistryKey(Win32Registry.ClassesRoot);
10 | public IWindowsRegistryKey CurrentConfig => new WindowsRegistryKey(Win32Registry.CurrentConfig);
11 | public IWindowsRegistryKey CurrentUser => new WindowsRegistryKey(Win32Registry.CurrentUser);
12 | public IWindowsRegistryKey LocalMachine => new WindowsRegistryKey(Win32Registry.LocalMachine);
13 | public IWindowsRegistryKey PerformanceData => new WindowsRegistryKey(Win32Registry.PerformanceData);
14 | public IWindowsRegistryKey Users => new WindowsRegistryKey(Win32Registry.Users);
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/Extensions/ResourceExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public static class ResourceExtensions
4 | {
5 | public static IResourceBuilder OnError(this IResourceBuilder builder, ErrorOptions options)
6 | where T : Resource
7 | {
8 | builder.Configure(res => res.Error = options);
9 | return builder;
10 | }
11 |
12 | public static IResourceBuilder OnReboot(this IResourceBuilder builder, RebootOptions options)
13 | where T : Resource
14 | {
15 | builder.Configure(res => res.Reboot = options);
16 | return builder;
17 | }
18 |
19 | public static IResourceBuilder RequireAdministrator(this IResourceBuilder builder)
20 | where T : Resource
21 | {
22 | builder.Configure(res => res.RequireAdministrator = true);
23 | return builder;
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Cupboard/ExecutionPlan.cs:
--------------------------------------------------------------------------------
1 | using System.Collections;
2 | using System.Collections.Generic;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | internal sealed class ExecutionPlan : IEnumerable
7 | {
8 | private readonly IReadOnlyList _resources;
9 |
10 | public bool RequiresAdministrator { get; }
11 | public int Count => _resources.Count;
12 |
13 | public ExecutionPlan(
14 | IEnumerable resources,
15 | bool requiresAdministrator)
16 | {
17 | _resources = resources.ToReadOnlyList();
18 | RequiresAdministrator = requiresAdministrator;
19 | }
20 |
21 | public IEnumerator GetEnumerator()
22 | {
23 | return _resources.GetEnumerator();
24 | }
25 |
26 | IEnumerator IEnumerable.GetEnumerator()
27 | {
28 | return GetEnumerator();
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Sandbox/Facts/RustFactProvider.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 | using Cupboard;
4 | using Spectre.Console.Cli;
5 | using Spectre.IO;
6 |
7 | namespace Sandbox
8 | {
9 | public sealed class RustFactProvider : IFactProvider
10 | {
11 | private readonly ICupboardFileSystem _fileSystem;
12 | private readonly ICupboardEnvironment _environment;
13 |
14 | public RustFactProvider(ICupboardFileSystem fileSystem, ICupboardEnvironment environment)
15 | {
16 | _fileSystem = fileSystem ?? throw new ArgumentNullException(nameof(fileSystem));
17 | _environment = environment ?? throw new ArgumentNullException(nameof(environment));
18 | }
19 |
20 | IEnumerable<(string Name, object Value)> IFactProvider.GetFacts(IRemainingArguments args)
21 | {
22 | var path = new DirectoryPath("~/.cargo").MakeAbsolute(_environment);
23 | yield return ("rust.installed", _fileSystem.Exist(path));
24 | }
25 | }
26 | }
27 |
--------------------------------------------------------------------------------
/src/Cupboard.Core/LogLevel.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public enum LogLevel
4 | {
5 | ///
6 | /// Severe errors that cause premature termination.
7 | ///
8 | Fatal,
9 |
10 | ///
11 | /// Other runtime errors or unexpected conditions.
12 | ///
13 | Error,
14 |
15 | ///
16 | /// Use of deprecated APIs, poor use of API, 'almost' errors, other runtime
17 | /// situations that are undesirable or unexpected, but not necessarily "wrong".
18 | ///
19 | Warning,
20 |
21 | ///
22 | /// Interesting runtime events.
23 | ///
24 | Information,
25 |
26 | ///
27 | /// Detailed information on the flow through the system.
28 | ///
29 | Verbose,
30 |
31 | ///
32 | /// Most detailed information.
33 | ///
34 | Debug,
35 | }
36 | }
37 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers/ResourcesModule.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class ResourcesModule : ServiceModule
6 | {
7 | public override void Configure(IServiceCollection services)
8 | {
9 | // Resources
10 | services.AddSingleton();
11 | services.AddSingleton();
12 | services.AddSingleton();
13 | services.AddSingleton();
14 | services.AddSingleton();
15 | services.AddSingleton();
16 |
17 | // Facts
18 | services.AddSingleton();
19 | services.AddSingleton();
20 | services.AddSingleton();
21 | }
22 | }
23 | }
24 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/WindowsModule.cs:
--------------------------------------------------------------------------------
1 | using Microsoft.Extensions.DependencyInjection;
2 |
3 | namespace Cupboard
4 | {
5 | public sealed class WindowsModule : ServiceModule
6 | {
7 | public override void Configure(IServiceCollection services)
8 | {
9 | // Resources
10 | services.AddSingleton();
11 | services.AddSingleton();
12 | services.AddSingleton();
13 | services.AddSingleton();
14 |
15 | #pragma warning disable CS0618 // Type or member is obsolete
16 | services.AddSingleton();
17 | #pragma warning restore CS0618 // Type or member is obsolete
18 |
19 | // Facts
20 | services.AddSingleton();
21 | services.AddSingleton();
22 | }
23 | }
24 | }
25 |
--------------------------------------------------------------------------------
/src/Cupboard.Providers.Windows/Winget/WingetPackageExtensions.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard
2 | {
3 | public static class WingetPackageExtensions
4 | {
5 | public static IResourceBuilder Ensure(this IResourceBuilder builder, PackageState state)
6 | {
7 | return builder.Configure(pkg => pkg.Ensure = state);
8 | }
9 |
10 | public static IResourceBuilder Package(this IResourceBuilder builder, string package)
11 | {
12 | return builder.Configure(pkg => pkg.Package = package);
13 | }
14 |
15 | public static IResourceBuilder Force(this IResourceBuilder builder, bool force)
16 | {
17 | return builder.Configure(pkg => pkg.Force = force);
18 | }
19 |
20 | public static IResourceBuilder PackageVersion(this IResourceBuilder builder, string version)
21 | {
22 | return builder.Configure(pkg => pkg.PackageVersion = version);
23 | }
24 | }
25 | }
26 |
--------------------------------------------------------------------------------
/src/Cupboard/Cupboard.csproj:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 | net5.0
5 | 9.0
6 | enable
7 | true
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
25 |
26 |
27 |
28 |
29 |
--------------------------------------------------------------------------------
/src/Cupboard/ResourceProviderRepository.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using System.Collections.Generic;
3 |
4 | namespace Cupboard.Internal
5 | {
6 | internal sealed class ResourceProviderRepository
7 | {
8 | private readonly Dictionary _lookup;
9 |
10 | public ResourceProviderRepository(IEnumerable providers)
11 | {
12 | _lookup = new Dictionary();
13 | foreach (var provider in providers)
14 | {
15 | if (_lookup.ContainsKey(provider.ResourceType))
16 | {
17 | throw new InvalidOperationException(
18 | $"Encountered duplicate providers for {provider.ResourceType}");
19 | }
20 |
21 | _lookup.Add(provider.ResourceType, provider);
22 | }
23 | }
24 |
25 | public IResourceProvider? GetProvider(Type type)
26 | {
27 | _lookup.TryGetValue(type, out var provider);
28 | return provider;
29 | }
30 | }
31 | }
32 |
--------------------------------------------------------------------------------
/src/Cupboard.Testing/Fakes/FakeWindowsRegistry.cs:
--------------------------------------------------------------------------------
1 | namespace Cupboard.Testing
2 | {
3 | public sealed class FakeWindowsRegistry : IWindowsRegistry
4 | {
5 | public IWindowsRegistryKey ClassesRoot { get; }
6 | public IWindowsRegistryKey CurrentConfig { get; }
7 | public IWindowsRegistryKey CurrentUser { get; }
8 | public IWindowsRegistryKey LocalMachine { get; }
9 | public IWindowsRegistryKey PerformanceData { get; }
10 | public IWindowsRegistryKey Users { get; }
11 |
12 | public FakeWindowsRegistry()
13 | {
14 | ClassesRoot = new FakeWindowsRegistryKey(new RegistryPath("HKCR"));
15 | CurrentConfig = new FakeWindowsRegistryKey(new RegistryPath("HKCC"));
16 | CurrentUser = new FakeWindowsRegistryKey(new RegistryPath("HKCU"));
17 | LocalMachine = new FakeWindowsRegistryKey(new RegistryPath("HKLM"));
18 | PerformanceData = new FakeWindowsRegistryKey(new RegistryPath("HKPD"));
19 | Users = new FakeWindowsRegistryKey(new RegistryPath("HKU"));
20 | }
21 | }
22 | }
23 |
--------------------------------------------------------------------------------
/src/Cupboard/Cli/Infrastructure/TypeRegistrar.cs:
--------------------------------------------------------------------------------
1 | using System;
2 | using Microsoft.Extensions.DependencyInjection;
3 | using Spectre.Console.Cli;
4 |
5 | namespace Cupboard.Internal
6 | {
7 | internal sealed class TypeRegistrar : ITypeRegistrar
8 | {
9 | private readonly IServiceCollection _provider;
10 |
11 | public TypeRegistrar(IServiceCollection provider)
12 | {
13 | _provider = provider;
14 | }
15 |
16 | public ITypeResolver Build()
17 | {
18 | return new TypeResolver(_provider.BuildServiceProvider());
19 | }
20 |
21 | public void Register(Type service, Type implementation)
22 | {
23 | _provider.AddSingleton(service, implementation);
24 | }
25 |
26 | public void RegisterInstance(Type service, object implementation)
27 | {
28 | _provider.AddSingleton(service, implementation);
29 | }
30 |
31 | public void RegisterLazy(Type service, Func