Skip to content

Commit 2f344f0

Browse files
authored
Dscv3 command base (#5280)
## Change Adds infrastructure for writing DSC v3 resource commands. Adds a new hidden command `dscv3` to put the resources under. Adds a file content resource (`DscTestFileResource`) that is only available when tests hooks are enabled. The resource infrastructure generates the resource manifest based on the defined functions and modifiers given to the base via `winget dscv3 <resource> --manifest`. It directs the `DscFunctions` it is given to the appropriate virtual method (`--get` maps to `ResourceFunctionGet`). Resources can define properties using the helper macro `WINGET_DSC_DEFINE_COMPOSABLE_PROPERTY` and create an object to represent their properties with `DscComposableObject`. This makes extracting and writing properties to JSON easy, as well as generating a schema.
1 parent a3cea27 commit 2f344f0

40 files changed

+1325
-128
lines changed

src/AppInstallerCLICore/AppInstallerCLICore.vcxproj

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -302,6 +302,10 @@
302302
<ClInclude Include="Commands\ConfigureValidateCommand.h" />
303303
<ClInclude Include="Commands\DebugCommand.h" />
304304
<ClInclude Include="Commands\DownloadCommand.h" />
305+
<ClInclude Include="Commands\DscCommand.h" />
306+
<ClInclude Include="Commands\DscCommandBase.h" />
307+
<ClInclude Include="Commands\DscComposableObject.h" />
308+
<ClInclude Include="Commands\DscTestFileResource.h" />
305309
<ClInclude Include="Commands\ErrorCommand.h" />
306310
<ClInclude Include="Commands\ExperimentalCommand.h" />
307311
<ClInclude Include="Commands\ExportCommand.h" />
@@ -383,6 +387,10 @@
383387
<ClCompile Include="Commands\ConfigureValidateCommand.cpp" />
384388
<ClCompile Include="Commands\DebugCommand.cpp" />
385389
<ClCompile Include="Commands\DownloadCommand.cpp" />
390+
<ClCompile Include="Commands\DscCommand.cpp" />
391+
<ClCompile Include="Commands\DscCommandBase.cpp" />
392+
<ClCompile Include="Commands\DscComposableObject.cpp" />
393+
<ClCompile Include="Commands\DscTestFileResource.cpp" />
386394
<ClCompile Include="Commands\ErrorCommand.cpp" />
387395
<ClCompile Include="Commands\FontCommand.cpp" />
388396
<ClCompile Include="Commands\ImportCommand.cpp" />

src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters

Lines changed: 63 additions & 36 deletions
Original file line numberDiff line numberDiff line change
@@ -18,6 +18,9 @@
1818
<Filter Include="Workflows">
1919
<UniqueIdentifier>{fdeb940e-93e2-4bb0-a59c-1e2d1c0588d1}</UniqueIdentifier>
2020
</Filter>
21+
<Filter Include="Commands\Configuration">
22+
<UniqueIdentifier>{bd9d8dfe-7a37-4a53-b4e7-ddbd9694c0ab}</UniqueIdentifier>
23+
</Filter>
2124
</ItemGroup>
2225
<ItemGroup>
2326
<ClInclude Include="pch.h">
@@ -197,18 +200,6 @@
197200
<ClInclude Include="Workflows\MultiQueryFlow.h">
198201
<Filter>Workflows</Filter>
199202
</ClInclude>
200-
<ClInclude Include="Commands\ConfigureCommand.h">
201-
<Filter>Commands</Filter>
202-
</ClInclude>
203-
<ClInclude Include="Commands\ConfigureShowCommand.h">
204-
<Filter>Commands</Filter>
205-
</ClInclude>
206-
<ClInclude Include="Commands\ConfigureTestCommand.h">
207-
<Filter>Commands</Filter>
208-
</ClInclude>
209-
<ClInclude Include="Commands\ConfigureValidateCommand.h">
210-
<Filter>Commands</Filter>
211-
</ClInclude>
212203
<ClInclude Include="ConfigurationContext.h">
213204
<Filter>Header Files</Filter>
214205
</ClInclude>
@@ -251,12 +242,6 @@
251242
<ClInclude Include="ConfigurationWingetDscModuleUnitValidation.h">
252243
<Filter>Header Files</Filter>
253244
</ClInclude>
254-
<ClInclude Include="ConfigureExportCommand.h">
255-
<Filter>Commands</Filter>
256-
</ClInclude>
257-
<ClInclude Include="Commands\ConfigureListCommand.h">
258-
<Filter>Commands</Filter>
259-
</ClInclude>
260245
<ClInclude Include="Sixel.h">
261246
<Filter>Header Files</Filter>
262247
</ClInclude>
@@ -266,6 +251,36 @@
266251
<ClInclude Include="Workflows\FontFlow.h">
267252
<Filter>Workflows</Filter>
268253
</ClInclude>
254+
<ClInclude Include="Commands\ConfigureCommand.h">
255+
<Filter>Commands\Configuration</Filter>
256+
</ClInclude>
257+
<ClInclude Include="ConfigureExportCommand.h">
258+
<Filter>Commands\Configuration</Filter>
259+
</ClInclude>
260+
<ClInclude Include="Commands\ConfigureListCommand.h">
261+
<Filter>Commands\Configuration</Filter>
262+
</ClInclude>
263+
<ClInclude Include="Commands\ConfigureShowCommand.h">
264+
<Filter>Commands\Configuration</Filter>
265+
</ClInclude>
266+
<ClInclude Include="Commands\ConfigureTestCommand.h">
267+
<Filter>Commands\Configuration</Filter>
268+
</ClInclude>
269+
<ClInclude Include="Commands\ConfigureValidateCommand.h">
270+
<Filter>Commands\Configuration</Filter>
271+
</ClInclude>
272+
<ClInclude Include="Commands\DscCommand.h">
273+
<Filter>Commands\Configuration</Filter>
274+
</ClInclude>
275+
<ClInclude Include="Commands\DscCommandBase.h">
276+
<Filter>Commands\Configuration</Filter>
277+
</ClInclude>
278+
<ClInclude Include="Commands\DscTestFileResource.h">
279+
<Filter>Commands\Configuration</Filter>
280+
</ClInclude>
281+
<ClInclude Include="Commands\DscComposableObject.h">
282+
<Filter>Commands\Configuration</Filter>
283+
</ClInclude>
269284
</ItemGroup>
270285
<ItemGroup>
271286
<ClCompile Include="pch.cpp">
@@ -430,18 +445,6 @@
430445
<ClCompile Include="Workflows\MultiQueryFlow.cpp">
431446
<Filter>Workflows</Filter>
432447
</ClCompile>
433-
<ClCompile Include="Commands\ConfigureCommand.cpp">
434-
<Filter>Commands</Filter>
435-
</ClCompile>
436-
<ClCompile Include="Commands\ConfigureShowCommand.cpp">
437-
<Filter>Commands</Filter>
438-
</ClCompile>
439-
<ClCompile Include="Commands\ConfigureTestCommand.cpp">
440-
<Filter>Commands</Filter>
441-
</ClCompile>
442-
<ClCompile Include="Commands\ConfigureValidateCommand.cpp">
443-
<Filter>Commands</Filter>
444-
</ClCompile>
445448
<ClCompile Include="ConfigurationContext.cpp">
446449
<Filter>Source Files</Filter>
447450
</ClCompile>
@@ -487,12 +490,6 @@
487490
<ClCompile Include="ConfigurationDynamicRuntimeFactory.cpp">
488491
<Filter>Source Files</Filter>
489492
</ClCompile>
490-
<ClCompile Include="ConfigureExportCommand.cpp">
491-
<Filter>Commands</Filter>
492-
</ClCompile>
493-
<ClCompile Include="Commands\ConfigureListCommand.cpp">
494-
<Filter>Commands</Filter>
495-
</ClCompile>
496493
<ClCompile Include="Sixel.cpp">
497494
<Filter>Source Files</Filter>
498495
</ClCompile>
@@ -502,6 +499,36 @@
502499
<ClCompile Include="Workflows\FontFlow.cpp">
503500
<Filter>Workflows</Filter>
504501
</ClCompile>
502+
<ClCompile Include="Commands\ConfigureCommand.cpp">
503+
<Filter>Commands\Configuration</Filter>
504+
</ClCompile>
505+
<ClCompile Include="ConfigureExportCommand.cpp">
506+
<Filter>Commands\Configuration</Filter>
507+
</ClCompile>
508+
<ClCompile Include="Commands\ConfigureListCommand.cpp">
509+
<Filter>Commands\Configuration</Filter>
510+
</ClCompile>
511+
<ClCompile Include="Commands\ConfigureShowCommand.cpp">
512+
<Filter>Commands\Configuration</Filter>
513+
</ClCompile>
514+
<ClCompile Include="Commands\ConfigureTestCommand.cpp">
515+
<Filter>Commands\Configuration</Filter>
516+
</ClCompile>
517+
<ClCompile Include="Commands\ConfigureValidateCommand.cpp">
518+
<Filter>Commands\Configuration</Filter>
519+
</ClCompile>
520+
<ClCompile Include="Commands\DscCommand.cpp">
521+
<Filter>Commands\Configuration</Filter>
522+
</ClCompile>
523+
<ClCompile Include="Commands\DscCommandBase.cpp">
524+
<Filter>Commands\Configuration</Filter>
525+
</ClCompile>
526+
<ClCompile Include="Commands\DscTestFileResource.cpp">
527+
<Filter>Commands\Configuration</Filter>
528+
</ClCompile>
529+
<ClCompile Include="Commands\DscComposableObject.cpp">
530+
<Filter>Commands\Configuration</Filter>
531+
</ClCompile>
505532
</ItemGroup>
506533
<ItemGroup>
507534
<None Include="PropertySheet.props" />

src/AppInstallerCLICore/Argument.cpp

Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -234,6 +234,30 @@ namespace AppInstaller::CLI
234234
case Execution::Args::Type::ConfigurationStatusWatch:
235235
return { type, "live"_liv };
236236

237+
// DSCv3 resources
238+
case Execution::Args::Type::DscResourceFunctionGet:
239+
return { type, "get"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
240+
case Execution::Args::Type::DscResourceFunctionSet:
241+
return { type, "set"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
242+
case Execution::Args::Type::DscResourceFunctionWhatIf:
243+
return { type, "whatIf"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
244+
case Execution::Args::Type::DscResourceFunctionTest:
245+
return { type, "test"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
246+
case Execution::Args::Type::DscResourceFunctionDelete:
247+
return { type, "delete"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
248+
case Execution::Args::Type::DscResourceFunctionExport:
249+
return { type, "export"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
250+
case Execution::Args::Type::DscResourceFunctionValidate:
251+
return { type, "validate"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
252+
case Execution::Args::Type::DscResourceFunctionResolve:
253+
return { type, "resolve"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
254+
case Execution::Args::Type::DscResourceFunctionAdapter:
255+
return { type, "adapter"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
256+
case Execution::Args::Type::DscResourceFunctionSchema:
257+
return { type, "schema"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
258+
case Execution::Args::Type::DscResourceFunctionManifest:
259+
return { type, "manifest"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::DscResourceFunction };
260+
237261
// Download command
238262
case Execution::Args::Type::DownloadDirectory:
239263
return { type, "download-directory"_liv, 'd', ArgTypeCategory::None };

src/AppInstallerCLICore/Argument.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -90,6 +90,7 @@ namespace AppInstaller::CLI
9090
Proxy = 0x20,
9191
AllAndTargetVersion = 0x40,
9292
ConfigurationSetChoice = 0x80,
93+
DscResourceFunction = 0x100,
9394

9495
// This must always be at the end
9596
Max

src/AppInstallerCLICore/Command.h

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -65,6 +65,8 @@ namespace AppInstaller::CLI
6565
Command(name, aliases, parent, Command::Visibility::Show, Settings::ExperimentalFeature::Feature::None, groupPolicy, CommandOutputFlags::None) {}
6666
Command(std::string_view name, std::vector<std::string_view> aliases, std::string_view parent, Command::Visibility visibility, Settings::ExperimentalFeature::Feature feature) :
6767
Command(name, aliases, parent, visibility, feature, Settings::TogglePolicy::Policy::None, CommandOutputFlags::None) {}
68+
Command(std::string_view name, std::vector<std::string_view> aliases, std::string_view parent, Command::Visibility visibility, Settings::TogglePolicy::Policy groupPolicy) :
69+
Command(name, aliases, parent, visibility, Settings::ExperimentalFeature::Feature::None, groupPolicy, CommandOutputFlags::None) {}
6870

6971
Command(std::string_view name,
7072
std::vector<std::string_view> aliases,
@@ -98,8 +100,8 @@ namespace AppInstaller::CLI
98100
std::vector<std::unique_ptr<Command>> GetVisibleCommands() const;
99101
std::vector<Argument> GetVisibleArguments() const;
100102

101-
virtual Resource::LocString ShortDescription() const { return {}; }
102-
virtual Resource::LocString LongDescription() const { return {}; }
103+
virtual Resource::LocString ShortDescription() const = 0;
104+
virtual Resource::LocString LongDescription() const = 0;
103105

104106
virtual void OutputIntroHeader(Execution::Reporter& reporter) const;
105107
virtual void OutputHelp(Execution::Reporter& reporter, const CommandException* exception = nullptr) const;

src/AppInstallerCLICore/Commands/COMCommand.h

Lines changed: 15 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ namespace AppInstaller::CLI
99
struct COMDownloadCommand final : public Command
1010
{
1111
constexpr static std::string_view CommandName = "download"sv;
12-
COMDownloadCommand(std::string_view parent) : Command(CommandName, parent) {}
12+
COMDownloadCommand(std::string_view parent) : Command(CommandName, parent) {}
13+
14+
CLI::Resource::LocString ShortDescription() const override { return {}; }
15+
CLI::Resource::LocString LongDescription() const override { return {}; }
1316

1417
protected:
1518
void ExecuteInternal(Execution::Context& context) const override;
@@ -19,7 +22,10 @@ namespace AppInstaller::CLI
1922
struct COMInstallCommand final : public Command
2023
{
2124
constexpr static std::string_view CommandName = "install"sv;
22-
COMInstallCommand(std::string_view parent) : Command(CommandName, parent) {}
25+
COMInstallCommand(std::string_view parent) : Command(CommandName, parent) {}
26+
27+
CLI::Resource::LocString ShortDescription() const override { return {}; }
28+
CLI::Resource::LocString LongDescription() const override { return {}; }
2329

2430
protected:
2531
void ExecuteInternal(Execution::Context& context) const override;
@@ -29,7 +35,10 @@ namespace AppInstaller::CLI
2935
struct COMUninstallCommand final : public Command
3036
{
3137
constexpr static std::string_view CommandName = "uninstall"sv;
32-
COMUninstallCommand(std::string_view parent) : Command(CommandName, parent) {}
38+
COMUninstallCommand(std::string_view parent) : Command(CommandName, parent) {}
39+
40+
CLI::Resource::LocString ShortDescription() const override { return {}; }
41+
CLI::Resource::LocString LongDescription() const override { return {}; }
3342

3443
protected:
3544
void ExecuteInternal(Execution::Context& context) const override;
@@ -41,6 +50,9 @@ namespace AppInstaller::CLI
4150
constexpr static std::string_view CommandName = "repair"sv;
4251
COMRepairCommand(std::string_view parent) : Command(CommandName, parent) {}
4352

53+
CLI::Resource::LocString ShortDescription() const override { return {}; }
54+
CLI::Resource::LocString LongDescription() const override { return {}; }
55+
4456
protected:
4557
void ExecuteInternal(Execution::Context& context) const override;
4658
};

src/AppInstallerCLICore/Commands/ConfigureCommand.h

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
// Licensed under the MIT License.
33
#pragma once
44
#include "Command.h"
5-
#include <winget/ExperimentalFeature.h>
65

76
namespace AppInstaller::CLI
87
{
Lines changed: 40 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,40 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
#include "pch.h"
4+
#include "DscCommand.h"
5+
6+
#ifndef AICLI_DISABLE_TEST_HOOKS
7+
#include "DscTestFileResource.h"
8+
#endif
9+
10+
namespace AppInstaller::CLI
11+
{
12+
std::vector<std::unique_ptr<Command>> DscCommand::GetCommands() const
13+
{
14+
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
15+
#ifndef AICLI_DISABLE_TEST_HOOKS
16+
std::make_unique<DscTestFileResource>(FullName()),
17+
#endif
18+
});
19+
}
20+
21+
Resource::LocString DscCommand::ShortDescription() const
22+
{
23+
return { Resource::String::DscCommandShortDescription };
24+
}
25+
26+
Resource::LocString DscCommand::LongDescription() const
27+
{
28+
return { Resource::String::DscCommandLongDescription };
29+
}
30+
31+
Utility::LocIndView DscCommand::HelpLink() const
32+
{
33+
return "https://aka.ms/winget-dsc-resources"_liv;
34+
}
35+
36+
void DscCommand::ExecuteInternal(Execution::Context& context) const
37+
{
38+
OutputHelp(context.Reporter);
39+
}
40+
}
Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,25 @@
1+
// Copyright (c) Microsoft Corporation.
2+
// Licensed under the MIT License.
3+
#pragma once
4+
#include "Command.h"
5+
#include <winget/ExperimentalFeature.h>
6+
7+
namespace AppInstaller::CLI
8+
{
9+
struct DscCommand final : public Command
10+
{
11+
DscCommand(std::string_view parent) : Command(StaticName(), parent, Settings::ExperimentalFeature::Feature::ConfigurationDSCv3) {}
12+
13+
static constexpr std::string_view StaticName() { return "dscv3"sv; };
14+
15+
std::vector<std::unique_ptr<Command>> GetCommands() const override;
16+
17+
Resource::LocString ShortDescription() const override;
18+
Resource::LocString LongDescription() const override;
19+
20+
Utility::LocIndView HelpLink() const override;
21+
22+
protected:
23+
void ExecuteInternal(Execution::Context& context) const override;
24+
};
25+
}

0 commit comments

Comments
 (0)