Skip to content

Commit fa43d1e

Browse files
committed
Try harder to respect --color/--no-color in presence of errors and assume --no-color when in doubt
1 parent 42770fc commit fa43d1e

File tree

2 files changed

+18
-6
lines changed

2 files changed

+18
-6
lines changed

solc/CommandLineInterface.cpp

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -658,7 +658,19 @@ bool CommandLineInterface::parseArguments(int _argc, char const* const* _argv)
658658
return false;
659659
}
660660

661-
parser.parse(_argc, _argv);
661+
try
662+
{
663+
parser.parse(_argc, _argv);
664+
}
665+
catch (...)
666+
{
667+
// Even if the overall CLI parsing fails, the --color/--no-color options may have been
668+
// successfully parsed, and if so, should be taken into account when printing errors.
669+
// If no value is present, it's possible that --no-color is still there but parsing failed
670+
// due to other, unrecognized options so play it safe and disable color in that case.
671+
m_options.formatting.coloredOutput = parser.options().formatting.coloredOutput.value_or(false);
672+
throw;
673+
}
662674
m_options = parser.options();
663675

664676
return true;

solc/CommandLineParser.cpp

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -917,6 +917,11 @@ void CommandLineParser::parseArgs(int _argc, char const* const* _argv)
917917

918918
void CommandLineParser::processArgs()
919919
{
920+
if (m_args.count(g_strColor) > 0)
921+
m_options.formatting.coloredOutput = true;
922+
else if (m_args.count(g_strNoColor) > 0)
923+
m_options.formatting.coloredOutput = false;
924+
920925
checkMutuallyExclusive({
921926
g_strHelp,
922927
g_strLicense,
@@ -1031,11 +1036,6 @@ void CommandLineParser::processArgs()
10311036
);
10321037
}
10331038

1034-
if (m_args.count(g_strColor) > 0)
1035-
m_options.formatting.coloredOutput = true;
1036-
else if (m_args.count(g_strNoColor) > 0)
1037-
m_options.formatting.coloredOutput = false;
1038-
10391039
m_options.formatting.withErrorIds = m_args.count(g_strErrorIds);
10401040

10411041
if (m_args.count(g_strRevertStrings))

0 commit comments

Comments
 (0)