Skip to content

Commit ed29780

Browse files
committed
Update bool conversion and arguments
1 parent d9bb591 commit ed29780

File tree

5 files changed

+19
-11
lines changed

5 files changed

+19
-11
lines changed

src/AppInstallerCLICore/Commands/SourceCommand.cpp

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -344,7 +344,8 @@ namespace AppInstaller::CLI
344344
if (execArgs.Contains(Execution::Args::Type::SourceEditExplicit))
345345
{
346346
std::string_view explicitArg = execArgs.GetArg(Execution::Args::Type::SourceEditExplicit);
347-
if (!Utility::CaseInsensitiveEquals(explicitArg, "true") && !Utility::CaseInsensitiveEquals(explicitArg, "false"))
347+
auto convertedArg = Utility::TryConvertStringToBool(explicitArg);
348+
if (!convertedArg.has_value())
348349
{
349350
auto validOptions = Utility::Join(", "_liv, std::vector<Utility::LocIndString>{
350351
"true"_lis,

src/AppInstallerCLICore/Workflows/SourceFlow.cpp

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -283,11 +283,10 @@ namespace AppInstaller::CLI::Workflow
283283
Repository::Source targetSource{ sd.Name };
284284
auto oldExplicitValue = sd.Explicit;
285285

286-
// Default to the current explicit value unless we are overriding it.
287-
auto isExplicit = oldExplicitValue;
286+
std::optional<bool> isExplicit;
288287
if (context.Args.Contains(Execution::Args::Type::SourceEditExplicit))
289288
{
290-
isExplicit = Utility::ConvertStringToBool(context.Args.GetArg(Execution::Args::Type::SourceEditExplicit));
289+
isExplicit = Utility::TryConvertStringToBool(context.Args.GetArg(Execution::Args::Type::SourceEditExplicit));
291290
}
292291

293292
Repository::SourceEdit edits{ std::optional<bool>{ isExplicit } };

src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3476,11 +3476,11 @@ An unlocalized JSON fragment will follow on another line.</comment>
34763476
<value>Font package is already installed.</value>
34773477
</data>
34783478
<data name="SourceEditOldValue" xml:space="preserve">
3479-
<value>Old value</value>
3479+
<value>Old Value</value>
34803480
<comment>Column title for listing edit changes.</comment>
34813481
</data>
34823482
<data name="SourceEditNewValue" xml:space="preserve">
3483-
<value>New value</value>
3483+
<value>New Value</value>
34843484
<comment>Column title for listing the new value.</comment>
34853485
</data>
34863486
</root>

src/AppInstallerSharedLib/AppInstallerStrings.cpp

Lines changed: 11 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -939,11 +939,18 @@ namespace AppInstaller::Utility
939939
return value ? "true"sv : "false"sv;
940940
}
941941

942-
bool ConvertStringToBool(const std::string_view& input)
942+
std::optional<bool> TryConvertStringToBool(const std::string_view& input)
943943
{
944-
bool value;
945-
std::istringstream(std::string(input)) >> std::boolalpha >> value;
946-
return value;
944+
try
945+
{
946+
bool value;
947+
std::istringstream(std::string(input)) >> std::boolalpha >> value;
948+
return { value };
949+
}
950+
catch
951+
{
952+
return {};
953+
}
947954
}
948955

949956
std::string ConvertGuidToString(const GUID& value)

src/AppInstallerSharedLib/Public/AppInstallerStrings.h

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,7 @@
33
#pragma once
44
#include <filesystem>
55
#include <ostream>
6+
#include <optional>
67
#include <string>
78
#include <string_view>
89
#include <vector>
@@ -291,7 +292,7 @@ namespace AppInstaller::Utility
291292
std::string_view ConvertBoolToString(bool value);
292293

293294
// Converts the given string view into a bool.
294-
bool ConvertStringToBool(const std::string_view& value);
295+
std::optional<bool> TryConvertStringToBool(const std::string_view& value);
295296

296297
// Converts the given GUID value to a string.
297298
std::string ConvertGuidToString(const GUID& value);

0 commit comments

Comments
 (0)