Skip to content

Commit 9221c20

Browse files
committed
Feedback update, rework string to bool
1 parent ed29780 commit 9221c20

File tree

14 files changed

+24
-111
lines changed

14 files changed

+24
-111
lines changed

src/AppInstallerCLICore/Workflows/SourceFlow.cpp

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -289,7 +289,7 @@ namespace AppInstaller::CLI::Workflow
289289
isExplicit = Utility::TryConvertStringToBool(context.Args.GetArg(Execution::Args::Type::SourceEditExplicit));
290290
}
291291

292-
Repository::SourceEdit edits{ std::optional<bool>{ isExplicit } };
292+
Repository::SourceEdit edits{ isExplicit };
293293
if (!targetSource.RequiresChanges(edits))
294294
{
295295
context.Reporter.Info() << Resource::String::SourceEditNoChanges(Utility::LocIndView{ sd.Name }) << std::endl;
@@ -301,7 +301,7 @@ namespace AppInstaller::CLI::Workflow
301301

302302
// Output updated source information. Since only Explicit is editable, we will only list that field. The name of the source being edited is listed prior to the edits.
303303
Execution::TableOutput<3> table(context.Reporter, { Resource::String::SourceListField, Resource::String::SourceEditOldValue, Resource::String::SourceEditNewValue });
304-
table.OutputLine({ Resource::LocString(Resource::String::SourceListExplicit), std::string{ Utility::ConvertBoolToString(oldExplicitValue) }, std::string{ Utility::ConvertBoolToString(isExplicit) } });
304+
table.OutputLine({ Resource::LocString(Resource::String::SourceListExplicit), std::string{ Utility::ConvertBoolToString(oldExplicitValue) }, std::string{ Utility::ConvertBoolToString(isExplicit.value()) } });
305305
table.Complete();
306306
}
307307
}

src/AppInstallerCLITests/TestSource.cpp

Lines changed: 0 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -454,15 +454,6 @@ namespace TestCommon
454454
return true;
455455
}
456456

457-
bool TestSourceFactory::Edit(SourceDetails& details, const SourceEdit& edits)
458-
{
459-
if (OnEdit)
460-
{
461-
OnEdit(details, edits);
462-
}
463-
return true;
464-
}
465-
466457
// Make copies of self when requested.
467458
TestSourceFactory::operator std::function<std::unique_ptr<ISourceFactory>()>()
468459
{
@@ -475,12 +466,6 @@ namespace TestCommon
475466
return source.Add(progress);
476467
}
477468

478-
bool EditSource(const AppInstaller::Repository::SourceDetails& details, const AppInstaller::Repository::SourceEdit& edits)
479-
{
480-
Repository::Source source{ details.Name, details.Explicit };
481-
return source.Edit(edits);
482-
}
483-
484469
bool UpdateSource(std::string_view name, AppInstaller::IProgressCallback& progress)
485470
{
486471
Repository::Source source{ name };

src/AppInstallerCLITests/TestSource.h

Lines changed: 0 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -187,7 +187,6 @@ namespace TestCommon
187187
using AddFunctor = std::function<void(AppInstaller::Repository::SourceDetails&)>;
188188
using UpdateFunctor = std::function<void(const AppInstaller::Repository::SourceDetails&)>;
189189
using RemoveFunctor = std::function<void(const AppInstaller::Repository::SourceDetails&)>;
190-
using EditFunctor = std::function<void(AppInstaller::Repository::SourceDetails&, const AppInstaller::Repository::SourceEdit& edits)>;
191190

192191
TestSourceFactory(OpenFunctor open) : OnOpen(std::move(open)) {}
193192
TestSourceFactory(OpenFunctorWithCustomHeader open) : OnOpenWithCustomHeader(std::move(open)) {}
@@ -198,7 +197,6 @@ namespace TestCommon
198197
bool Add(AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override;
199198
bool Update(const AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override;
200199
bool Remove(const AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback&) override;
201-
bool Edit(AppInstaller::Repository::SourceDetails& details, const AppInstaller::Repository::SourceEdit& edits) override;
202200

203201
// Make copies of self when requested.
204202
operator std::function<std::unique_ptr<AppInstaller::Repository::ISourceFactory>()>();
@@ -209,11 +207,9 @@ namespace TestCommon
209207
AddFunctor OnAdd;
210208
UpdateFunctor OnUpdate;
211209
RemoveFunctor OnRemove;
212-
EditFunctor OnEdit;
213210
};
214211

215212
bool AddSource(const AppInstaller::Repository::SourceDetails& details, AppInstaller::IProgressCallback& progress);
216-
bool EditSource(AppInstaller::Repository::SourceDetails& details, const AppInstaller::Repository::SourceEdit& edits);
217213
bool UpdateSource(std::string_view name, AppInstaller::IProgressCallback& progress);
218214
bool RemoveSource(std::string_view name, AppInstaller::IProgressCallback& progress);
219215
AppInstaller::Repository::Source OpenSource(std::string_view name, AppInstaller::IProgressCallback& progress);

src/AppInstallerRepositoryCore/Microsoft/ConfigurableTestSourceFactory.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -154,11 +154,6 @@ namespace AppInstaller::Repository::Microsoft
154154
{
155155
return true;
156156
}
157-
158-
bool Edit(SourceDetails&, const SourceEdit&) override final
159-
{
160-
return true;
161-
}
162157
};
163158
}
164159

src/AppInstallerRepositoryCore/Microsoft/PreIndexedPackageSourceFactory.cpp

Lines changed: 0 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -254,17 +254,6 @@ namespace AppInstaller::Repository::Microsoft
254254
return UpdateBase(details, true, progress);
255255
}
256256

257-
// Applies the edits to the source.
258-
bool Edit(SourceDetails& details, const SourceEdit& edits) override final
259-
{
260-
if (edits.Explicit.has_value())
261-
{
262-
details.Explicit = edits.Explicit.value();
263-
}
264-
265-
return true;
266-
}
267-
268257
// Retrieves the currently cached version of the package.
269258
virtual std::optional<Msix::PackageVersion> GetCurrentVersion(const SourceDetails& details) = 0;
270259

src/AppInstallerRepositoryCore/Microsoft/PredefinedInstalledSourceFactory.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -445,11 +445,6 @@ namespace AppInstaller::Repository::Microsoft
445445
// Similar to add, remove should never be needed.
446446
THROW_HR(E_NOTIMPL);
447447
}
448-
449-
bool Edit(SourceDetails&, const SourceEdit&) override final
450-
{
451-
THROW_HR(E_NOTIMPL);
452-
}
453448
};
454449
}
455450

src/AppInstallerRepositoryCore/Microsoft/PredefinedWriteableSourceFactory.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -44,11 +44,6 @@ namespace AppInstaller::Repository::Microsoft
4444
// Similar to add, remove should never be needed.
4545
THROW_HR(E_NOTIMPL);
4646
}
47-
48-
bool Edit(SourceDetails&, const SourceEdit&) override final
49-
{
50-
THROW_HR(E_NOTIMPL);
51-
}
5247
};
5348

5449
struct PredefinedWriteableSourceReference : public ISourceReference

src/AppInstallerRepositoryCore/PackageTrackingCatalog.cpp

Lines changed: 0 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -125,11 +125,6 @@ namespace AppInstaller::Repository
125125
THROW_HR(E_NOTIMPL);
126126
}
127127

128-
bool Edit(SourceDetails&, const SourceEdit&) override final
129-
{
130-
THROW_HR(E_NOTIMPL);
131-
}
132-
133128
bool Remove(const SourceDetails& details, IProgressCallback& progress) override final
134129
{
135130
THROW_HR_IF(E_INVALIDARG, !Utility::CaseInsensitiveEquals(details.Type, PackageTrackingCatalogSourceFactory::Type()));

src/AppInstallerRepositoryCore/Public/winget/RepositorySource.h

Lines changed: 1 addition & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -233,9 +233,6 @@ namespace AppInstaller::Repository
233233
// Constructor for a source to be added.
234234
Source(std::string_view name, std::string_view arg, std::string_view type, SourceTrustLevel trustLevel, bool isExplicit);
235235

236-
// Constructor for a source to be edited.
237-
Source(std::string_view name, std::optional<bool> isExplicit);
238-
239236
// Constructor for creating a composite source from a list of available sources.
240237
Source(const std::vector<Source>& availableSources);
241238

@@ -343,7 +340,7 @@ namespace AppInstaller::Repository
343340
bool Remove(IProgressCallback& progress);
344341

345342
// Edit source. Source edit command.
346-
bool Edit(const SourceEdit& edits);
343+
void Edit(const SourceEdit& edits);
347344

348345
// Determines if this source is a valid edit of otherSource.
349346
// Returns true if this source qualifies as an edit of the other source.

src/AppInstallerRepositoryCore/RepositorySource.cpp

Lines changed: 8 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -135,12 +135,6 @@ namespace AppInstaller::Repository
135135
return AddOrUpdateFromDetails(details, &ISourceFactory::Update, progress);
136136
}
137137

138-
bool EditSource(SourceDetails& details, const SourceEdit& edits)
139-
{
140-
auto factory = ISourceFactory::GetForType(details.Type);
141-
return factory->Edit(details, edits);
142-
}
143-
144138
AddOrUpdateResult BackgroundUpdateSourceFromDetails(SourceDetails& details, IProgressCallback& progress)
145139
{
146140
return AddOrUpdateFromDetails(details, &ISourceFactory::BackgroundUpdate, progress);
@@ -493,29 +487,6 @@ namespace AppInstaller::Repository
493487
m_sourceReferences.emplace_back(CreateSourceFromDetails(details));
494488
}
495489

496-
Source::Source(std::string_view name, std::optional<bool> isExplicit)
497-
{
498-
SourceList sourceList;
499-
auto source = sourceList.GetCurrentSource(name);
500-
if (!source)
501-
{
502-
AICLI_LOG(Repo, Info, << "Named source requested, but not found: " << name);
503-
}
504-
else
505-
{
506-
AICLI_LOG(Repo, Info, << "Named source requested, found: " << source->Name);
507-
508-
// This is intended to support Editing a source, and at present only the Explicit
509-
// property of SourceDetails can be edited.
510-
if (isExplicit.has_value())
511-
{
512-
source->Explicit = isExplicit.value();
513-
}
514-
515-
m_sourceReferences.emplace_back(CreateSourceFromDetails(*source));
516-
}
517-
}
518-
519490
Source::Source(const std::vector<Source>& availableSources)
520491
{
521492
std::shared_ptr<CompositeSource> compositeSource = std::make_shared<CompositeSource>("*CompositeSource");
@@ -1020,7 +991,7 @@ namespace AppInstaller::Repository
1020991
return result;
1021992
}
1022993

1023-
bool Source::Edit(const SourceEdit& edits)
994+
void Source::Edit(const SourceEdit& edits)
1024995
{
1025996
THROW_HR_IF(HRESULT_FROM_WIN32(ERROR_INVALID_STATE), m_isSourceToBeAdded || m_sourceReferences.size() != 1 || m_source);
1026997

@@ -1030,15 +1001,17 @@ namespace AppInstaller::Repository
10301001
// This is intentionally the same policy checks as Remove. If the source cannot be removed then it cannot be edited.
10311002
EnsureSourceIsRemovable(details);
10321003

1033-
// Apply the edits and update source list.
1034-
bool result = EditSource(details, edits);
1035-
if (result)
1004+
if (RequiresChanges(edits))
10361005
{
1006+
if (edits.Explicit.has_value())
1007+
{
1008+
details.Explicit = edits.Explicit.value();
1009+
}
1010+
1011+
// Apply the edits and update source list.
10371012
SourceList sourceList;
10381013
sourceList.EditSource(details);
10391014
}
1040-
1041-
return result;
10421015
}
10431016

10441017
bool Source::RequiresChanges(const SourceEdit& edits)

0 commit comments

Comments
 (0)