forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathDscCommand.cpp
More file actions
100 lines (85 loc) · 3.39 KB
/
DscCommand.cpp
File metadata and controls
100 lines (85 loc) · 3.39 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "DscCommand.h"
#include "DscPackageResource.h"
#include "DscUserSettingsFileResource.h"
#include "DscSourceResource.h"
#ifndef AICLI_DISABLE_TEST_HOOKS
#include "DscTestFileResource.h"
#include "DscTestJsonResource.h"
#endif
namespace AppInstaller::CLI
{
namespace
{
Argument GetOutputFileArgument()
{
return { Execution::Args::Type::OutputFile, Resource::String::OutputDirectoryArgumentDescription, ArgumentType::Standard };
}
}
DscCommand::DscCommand(std::string_view parent) :
Command(StaticName(), parent)
{
}
std::vector<std::unique_ptr<Command>> DscCommand::GetCommands() const
{
// These should all derive from DscCommandBase
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
std::make_unique<DscPackageResource>(FullName()),
std::make_unique<DscSourceResource>(FullName()),
std::make_unique<DscUserSettingsFileResource>(FullName()),
#ifndef AICLI_DISABLE_TEST_HOOKS
std::make_unique<DscTestFileResource>(FullName()),
std::make_unique<DscTestJsonResource>(FullName()),
#endif
});
}
std::vector<Argument> DscCommand::GetArguments() const
{
std::vector<Argument> result;
result.emplace_back(Execution::Args::Type::DscResourceFunctionManifest, Resource::String::DscResourceFunctionDescriptionManifest, ArgumentType::Flag);
result.emplace_back(GetOutputFileArgument());
return result;
}
Resource::LocString DscCommand::ShortDescription() const
{
return { Resource::String::DscCommandShortDescription };
}
Resource::LocString DscCommand::LongDescription() const
{
return { Resource::String::DscCommandLongDescription };
}
Utility::LocIndView DscCommand::HelpLink() const
{
return "https://aka.ms/winget-dsc-resources"_liv;
}
void DscCommand::ExecuteInternal(Execution::Context& context) const
{
if (context.Args.Contains(Execution::Args::Type::DscResourceFunctionManifest))
{
std::filesystem::path outputDirectory{ Utility::ConvertToUTF16(context.Args.GetArg(Execution::Args::Type::OutputFile)) };
std::filesystem::create_directories(outputDirectory);
std::string filePrefix = Utility::ToLower(DscCommandBase::ModuleName());
for (const auto& command : GetCommands())
{
DscCommandBase* commandBase = static_cast<DscCommandBase*>(command.get());
std::filesystem::path outputPath = outputDirectory;
outputPath /= std::string{ filePrefix }.append(".").append(commandBase->Name()).append(".dsc.resource.json");
commandBase->WriteManifest(context, outputPath);
}
}
else
{
OutputHelp(context.Reporter);
}
}
void DscCommand::ValidateArgumentsInternal(Execution::Args& args) const
{
if (args.Contains(Execution::Args::Type::DscResourceFunctionManifest) &&
!args.Contains(Execution::Args::Type::OutputFile))
{
throw CommandException(Resource::String::RequiredArgError(GetOutputFileArgument().Name()));
}
}
}