Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Make Ignore Warnings suppress the output level entirely #4221

Merged
merged 15 commits into from
Mar 15, 2024
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -393,6 +393,7 @@ namespace AppInstaller::CLI
args.push_back(ForType(Args::Type::RainbowStyle));
args.push_back(ForType(Args::Type::RetroStyle));
args.push_back(ForType(Args::Type::VerboseLogs));
args.push_back(ForType(Args::Type::IgnoreWarnings));
args.emplace_back(Args::Type::DisableInteractivity, Resource::String::DisableInteractivityArgumentDescription, ArgumentType::Flag, false);
}

Expand Down
1 change: 0 additions & 1 deletion src/AppInstallerCLICore/Commands/ValidateCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,6 @@ namespace AppInstaller::CLI
{
return {
Argument::ForType(Execution::Args::Type::ValidateManifest),
Argument::ForType(Execution::Args::Type::IgnoreWarnings),
};
}

Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLICore/Core.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -126,6 +126,12 @@ namespace AppInstaller::CLI
Logging::Log().SetLevel(Logging::Level::Verbose);
}

// Disable warnings if requested
if (context.Args.Contains(Execution::Args::Type::IgnoreWarnings))
{
context.Reporter.SetLevelEnabled(Execution::Reporter::Level::Warning, false);
}

context.UpdateForArgs();
context.SetExecutingCommand(command.get());
command->ValidateArguments(context.Args);
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -54,6 +54,12 @@ namespace AppInstaller::CLI::Execution

OutputStream Reporter::GetOutputStream(Level level)
{
// If the level is not enabled, return a default stream which is disabled
if (!levelEnabled(level))
Trenly marked this conversation as resolved.
Show resolved Hide resolved
{
return OutputStream(*m_out, false, false);
}

OutputStream result = GetBasicOutputStream();

switch (level)
Expand Down
24 changes: 24 additions & 0 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -165,9 +165,30 @@ namespace AppInstaller::CLI::Execution
m_progressSink = sink;
}

void SetLevelEnabled(Level reporterLevel, bool setEnabled = true) {
const bool isEnabled = levelEnabled(reporterLevel);
Trenly marked this conversation as resolved.
Show resolved Hide resolved
// If the reporter is already in the state we want, do nothing
if (isEnabled == setEnabled)
{
return;
}
if (setEnabled) {
// Add the level to the list of enabled levels
m_enabledLevels.push_back(reporterLevel);
}
else {
// Remove the level from the list of enabled levels
m_enabledLevels.erase(std::remove(m_enabledLevels.begin(), m_enabledLevels.end(), reporterLevel), m_enabledLevels.end());
}
}

private:
Reporter(std::shared_ptr<BaseStream> outStream, std::istream& inStream);

bool levelEnabled(Level reporterLevel) {
Trenly marked this conversation as resolved.
Show resolved Hide resolved
return std::find(m_enabledLevels.begin(), m_enabledLevels.end(), reporterLevel) != m_enabledLevels.end();
}

// Gets a stream for output for internal use.
OutputStream GetBasicOutputStream();

Expand All @@ -180,6 +201,9 @@ namespace AppInstaller::CLI::Execution
wil::srwlock m_progressCallbackLock;
std::atomic<ProgressCallback*> m_progressCallback;
std::atomic<IProgressSink*> m_progressSink;

// Enable all levels by default
std::vector<Level> m_enabledLevels = { Level::Verbose, Level::Info, Level::Warning, Level::Error };
Trenly marked this conversation as resolved.
Show resolved Hide resolved
};

// Indirection to enable change without tracking down every place
Expand Down
Loading