forked from microsoft/winget-cli
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathShowFlow.cpp
More file actions
254 lines (222 loc) · 13.9 KB
/
Copy pathShowFlow.cpp
File metadata and controls
254 lines (222 loc) · 13.9 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
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "ShowFlow.h"
#include <winget/ManifestComparator.h>
#include "TableOutput.h"
using namespace AppInstaller::Repository;
using namespace AppInstaller::CLI;
using namespace AppInstaller::Utility;
using namespace AppInstaller::Utility::literals;
namespace AppInstaller::CLI::Workflow
{
namespace
{
void ShowSingleLineField(Execution::OutputStream& outputStream, StringResource::StringId label, const Manifest::Manifest::string_t& value, bool indent = false)
{
Workflow::ShowSingleLineField(outputStream, label, LocIndView{ value }, indent ? 1 : 0);
}
void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, const Manifest::Manifest::string_t& value)
{
Workflow::ShowMultiLineField(outputStream, label, LocIndView{ value });
}
void ShowAgreements(Execution::OutputStream& outputStream, const std::vector<Manifest::Agreement>& agreements) {
if (agreements.empty()) {
return;
}
outputStream << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelAgreements << std::endl;
for (const auto& agreement : agreements) {
if (!agreement.Label.empty())
{
outputStream << " "_liv << Execution::ManifestInfoEmphasis << agreement.Label << ": "_liv;
}
if (!agreement.AgreementText.empty())
{
outputStream << agreement.AgreementText << std::endl;
}
if (!agreement.AgreementUrl.empty())
{
outputStream << agreement.AgreementUrl << std::endl;
}
}
}
}
namespace details
{
LocIndView GetIndentFor(size_t indentLevel)
{
static constexpr std::array<LocIndView, 4> s_indents{ ""_liv, " "_liv, " "_liv, " "_liv };
return s_indents.at(indentLevel);
}
}
void ShowAgreementsInfo(Execution::Context& context)
{
const auto& manifest = context.Get<Execution::Data::Manifest>();
auto info = context.Reporter.Info();
ShowSingleLineField(info, Resource::String::ShowLabelVersion, manifest.Version);
ShowSingleLineField(info, Resource::String::ShowLabelPublisher, manifest.CurrentLocalization.Get<Manifest::Localization::Publisher>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherSupportUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelAuthor, manifest.CurrentLocalization.Get<Manifest::Localization::Author>());
ShowSingleLineField(info, Resource::String::ShowLabelPackageUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelLicense, manifest.CurrentLocalization.Get<Manifest::Localization::License>());
ShowSingleLineField(info, Resource::String::ShowLabelLicenseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPrivacyUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyright, manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyrightUrl, manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPurchaseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PurchaseUrl>());
ShowAgreements(info, manifest.CurrentLocalization.Get<Manifest::Localization::Agreements>());
}
void ShowManifestInfo(Execution::Context& context)
{
context << ShowPackageInfo << ShowInstallerInfo;
}
void ShowPackageInfo(Execution::Context& context)
{
const auto& manifest = context.Get<Execution::Data::Manifest>();
auto info = context.Reporter.Info();
// Get description from manifest so we can see if it is empty later
auto description = manifest.CurrentLocalization.Get<Manifest::Localization::Description>();
// TODO: Come up with a prettier format
ShowSingleLineField(info, Resource::String::ShowLabelVersion, manifest.Version);
ShowSingleLineField(info, Resource::String::ShowLabelPublisher, manifest.CurrentLocalization.Get<Manifest::Localization::Publisher>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPublisherSupportUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PublisherSupportUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelAuthor, manifest.CurrentLocalization.Get<Manifest::Localization::Author>());
ShowSingleLineField(info, Resource::String::ShowLabelMoniker, manifest.Moniker);
ShowMultiLineField(info, Resource::String::ShowLabelDescription, description.empty() ? manifest.CurrentLocalization.Get<Manifest::Localization::ShortDescription>() : description);
ShowSingleLineField(info, Resource::String::ShowLabelPackageUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PackageUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelLicense, manifest.CurrentLocalization.Get<Manifest::Localization::License>());
ShowSingleLineField(info, Resource::String::ShowLabelLicenseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::LicenseUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPrivacyUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PrivacyUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyright, manifest.CurrentLocalization.Get<Manifest::Localization::Copyright>());
ShowSingleLineField(info, Resource::String::ShowLabelCopyrightUrl, manifest.CurrentLocalization.Get<Manifest::Localization::CopyrightUrl>());
ShowMultiLineField(info, Resource::String::ShowLabelReleaseNotes, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotes>());
ShowSingleLineField(info, Resource::String::ShowLabelReleaseNotesUrl, manifest.CurrentLocalization.Get<Manifest::Localization::ReleaseNotesUrl>());
ShowSingleLineField(info, Resource::String::ShowLabelPurchaseUrl, manifest.CurrentLocalization.Get<Manifest::Localization::PurchaseUrl>());
ShowMultiLineField(info, Resource::String::ShowLabelInstallationNotes, manifest.CurrentLocalization.Get<Manifest::Localization::InstallationNotes>());
const auto& documentations = manifest.CurrentLocalization.Get<Manifest::Localization::Documentations>();
if (!documentations.empty())
{
context.Reporter.Info() << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelDocumentation << std::endl;
for (const auto& documentation : documentations)
{
if (!documentation.DocumentUrl.empty())
{
info << " "_liv;
if (!documentation.DocumentLabel.empty())
{
info << Execution::ManifestInfoEmphasis << documentation.DocumentLabel << ": "_liv;
}
info << documentation.DocumentUrl << std::endl;
}
}
}
ShowMultiValueField(info, Resource::String::ShowLabelTags, manifest.CurrentLocalization.Get<Manifest::Localization::Tags>());
ShowAgreements(info, manifest.CurrentLocalization.Get<Manifest::Localization::Agreements>());
}
void ShowInstallerInfo(Execution::Context& context)
{
const auto& installer = context.Get<Execution::Data::Installer>();
auto info = context.Reporter.Info();
info << Execution::ManifestInfoEmphasis << Resource::String::ShowLabelInstaller << std::endl;
if (installer)
{
Manifest::InstallerTypeEnum effectiveInstallerType = installer->EffectiveInstallerType();
Manifest::InstallerTypeEnum baseInstallerType = installer->BaseInstallerType;
std::string shownInstallerType;
shownInstallerType = Manifest::InstallerTypeToString(effectiveInstallerType);
if (effectiveInstallerType != baseInstallerType)
{
shownInstallerType += " ("_liv;
shownInstallerType += Manifest::InstallerTypeToString(baseInstallerType);
shownInstallerType += ')';
}
ShowSingleLineField(info, Resource::String::ShowLabelInstallerType, shownInstallerType, true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerLocale, installer->Locale, true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerUrl, installer->Url, true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerSha256, (installer->Sha256.empty()) ? "" : Utility::SHA256::ConvertToString(installer->Sha256), true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerProductId, installer->ProductId, true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerReleaseDate, installer->ReleaseDate, true);
ShowSingleLineField(info, Resource::String::ShowLabelInstallerOfflineDistributionSupported, Utility::ConvertBoolToString(!installer->DownloadCommandProhibited), true);
const auto& dependencies = installer->Dependencies;
if (dependencies.HasAny())
{
info << Execution::ManifestInfoEmphasis << " "_liv << Resource::String::ShowLabelDependencies << ' ' << std::endl;
if (dependencies.HasAnyOf(Manifest::DependencyType::WindowsFeature))
{
info << " - "_liv << Resource::String::ShowLabelWindowsFeaturesDependencies << ' ' << std::endl;
dependencies.ApplyToType(Manifest::DependencyType::WindowsFeature, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id() << std::endl; });
}
if (dependencies.HasAnyOf(Manifest::DependencyType::WindowsLibrary))
{
info << " - "_liv << Resource::String::ShowLabelWindowsLibrariesDependencies << ' ' << std::endl;
dependencies.ApplyToType(Manifest::DependencyType::WindowsLibrary, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id() << std::endl; });
}
if (dependencies.HasAnyOf(Manifest::DependencyType::Package))
{
info << " - "_liv << Resource::String::ShowLabelPackageDependencies << ' ' << std::endl;
dependencies.ApplyToType(Manifest::DependencyType::Package, [&info](Manifest::Dependency dependency)
{
info << " "_liv << dependency.Id();
if (dependency.MinVersion)
{
info << " [>= " << dependency.MinVersion.value().ToString() << "]";
}
info << std::endl;
});
}
if (dependencies.HasAnyOf(Manifest::DependencyType::External))
{
info << " - "_liv << Resource::String::ShowLabelExternalDependencies << ' ' << std::endl;
dependencies.ApplyToType(Manifest::DependencyType::External, [&info](Manifest::Dependency dependency) {info << " "_liv << dependency.Id() << std::endl; });
}
}
}
else
{
context.Reporter.Warn() << " "_liv << Resource::String::NoApplicableInstallers << std::endl;
}
}
void ShowManifestVersion(Execution::Context& context)
{
const auto& manifest = context.Get<Execution::Data::Manifest>();
Execution::TableOutput<2> table(context.Reporter, { Resource::String::ShowVersion, Resource::String::ShowChannel });
table.OutputLine({ manifest.Version, manifest.Channel });
table.Complete();
}
void GetManifest::operator()(Execution::Context& context) const
{
if (context.Args.Contains(Execution::Args::Type::Manifest))
{
context <<
GetManifestFromArg;
}
else
{
context <<
OpenSource() <<
SearchSourceForSingle <<
HandleSearchResultFailures <<
EnsureOneMatchFromSearchResult(OperationType::Show) <<
GetManifestFromPackage(m_considerPins);
}
}
void ShowSingleLineField(Execution::OutputStream& outputStream, StringResource::StringId label, LocIndView value, size_t indentLevel)
{
if (value.empty())
{
return;
}
outputStream << details::GetIndentFor(indentLevel) << Execution::ManifestInfoEmphasis << label << ' ' << value << '\n';
}
void ShowMultiLineField(Execution::OutputStream& outputStream, StringResource::StringId label, LocIndView value, size_t indentLevel)
{
if (value.empty())
{
return;
}
// Treat the lines as separate values for the field
ShowMultiValueField(outputStream, label, Split(value, '\n'), indentLevel);
}
}