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::ReporterLevel::Warning, false);
}

context.UpdateForArgs();
context.SetExecutingCommand(command.get());
command->ValidateArguments(context.Args);
Expand Down
22 changes: 14 additions & 8 deletions src/AppInstallerCLICore/ExecutionReporter.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -52,22 +52,28 @@ namespace AppInstaller::CLI::Execution
}
}

OutputStream Reporter::GetOutputStream(Level level)
OutputStream Reporter::GetOutputStream(ReporterLevel level)
{
// If the level is not enabled, return a default stream which is disabled
if (WI_AreAllFlagsClear(m_enabledLevels, level))
{
return OutputStream(*m_out, false, false);
}

OutputStream result = GetBasicOutputStream();

switch (level)
{
case Level::Verbose:
case ReporterLevel::Verbose:
result.AddFormat(TextFormat::Default);
break;
case Level::Info:
case ReporterLevel::Info:
result.AddFormat(TextFormat::Default);
break;
case Level::Warning:
case ReporterLevel::Warning:
result.AddFormat(TextFormat::Foreground::BrightYellow);
break;
case Level::Error:
case ReporterLevel::Error:
result.AddFormat(TextFormat::Foreground::BrightRed);
break;
default:
Expand Down Expand Up @@ -111,7 +117,7 @@ namespace AppInstaller::CLI::Execution
}
}

bool Reporter::PromptForBoolResponse(Resource::LocString message, Level level)
bool Reporter::PromptForBoolResponse(Resource::LocString message, ReporterLevel level)
{
const std::vector<BoolPromptOption> options
{
Expand Down Expand Up @@ -161,14 +167,14 @@ namespace AppInstaller::CLI::Execution
}
}

void Reporter::PromptForEnter(Level level)
void Reporter::PromptForEnter(ReporterLevel level)
{
auto out = GetOutputStream(level);
out << std::endl << Resource::String::PressEnterToContinue << std::endl;
m_in.get();
}

std::filesystem::path Reporter::PromptForPath(Resource::LocString message, Level level)
std::filesystem::path Reporter::PromptForPath(Resource::LocString message, ReporterLevel level)
{
auto out = GetOutputStream(level);

Expand Down
53 changes: 35 additions & 18 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,18 @@ namespace AppInstaller::CLI::Execution
{
#define WINGET_OSTREAM_FORMAT_HRESULT(hr) "0x" << Logging::SetHRFormat << hr

// The level for the Output channel.
enum class ReporterLevel : uint32_t
{
None = 0x0,
Verbose = 0x1,
Info = 0x2,
Warning = 0x4,
Error = 0x8,
All = Verbose | Info | Warning | Error,
};
DEFINE_ENUM_FLAG_OPERATORS(ReporterLevel);
Trenly marked this conversation as resolved.
Show resolved Hide resolved

// One of the options available to the users when prompting for something.
struct BoolPromptOption
{
Expand All @@ -48,15 +60,6 @@ namespace AppInstaller::CLI::Execution
Disabled,
};

// The level for the Output channel.
enum class Level
{
Verbose,
Info,
Warning,
Error,
};

Reporter(std::ostream& outStream, std::istream& inStream);
Reporter(const Reporter&) = delete;
Reporter& operator=(const Reporter&) = delete;
Expand All @@ -71,22 +74,22 @@ namespace AppInstaller::CLI::Execution
~Reporter();

// Get a stream for verbose output.
OutputStream Verbose() { return GetOutputStream(Level::Verbose); }
OutputStream Verbose() { return GetOutputStream(ReporterLevel::Verbose); }

// Get a stream for informational output.
OutputStream Info() { return GetOutputStream(Level::Info); }
OutputStream Info() { return GetOutputStream(ReporterLevel::Info); }

// Get a stream for warning output.
OutputStream Warn() { return GetOutputStream(Level::Warning); }
OutputStream Warn() { return GetOutputStream(ReporterLevel::Warning); }

// Get a stream for error output.
OutputStream Error() { return GetOutputStream(Level::Error); }
OutputStream Error() { return GetOutputStream(ReporterLevel::Error); }

// Get a stream for outputting completion words.
OutputStream Completion() { return OutputStream(*m_out, m_channel == Channel::Completion, false); }

// Gets a stream for output of the given level.
OutputStream GetOutputStream(Level level);
OutputStream GetOutputStream(ReporterLevel level);

void EmptyLine() { GetBasicOutputStream() << std::endl; }

Expand All @@ -98,13 +101,13 @@ namespace AppInstaller::CLI::Execution
void SetStyle(AppInstaller::Settings::VisualStyle style);

// Prompts the user, return true if they consented.
bool PromptForBoolResponse(Resource::LocString message, Level level = Level::Info);
bool PromptForBoolResponse(Resource::LocString message, ReporterLevel level = ReporterLevel::Info);

// Prompts the user, continues when Enter is pressed
void PromptForEnter(Level level = Level::Info);
void PromptForEnter(ReporterLevel level = ReporterLevel::Info);

// Prompts the user for a path.
std::filesystem::path PromptForPath(Resource::LocString message, Level level = Level::Info);
std::filesystem::path PromptForPath(Resource::LocString message, ReporterLevel level = ReporterLevel::Info);

// Used to show indefinite progress. Currently an indefinite spinner is the form of
// showing indefinite progress.
Expand Down Expand Up @@ -165,9 +168,20 @@ namespace AppInstaller::CLI::Execution
m_progressSink = sink;
}

void SetLevelEnabled(ReporterLevel reporterLevel, bool setEnabled = true)
Trenly marked this conversation as resolved.
Show resolved Hide resolved
{
if (setEnabled)
{
WI_SetAllFlags(m_enabledLevels, reporterLevel);
}
else
{
WI_ClearAllFlags(m_enabledLevels, reporterLevel);
}
}

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

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

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

// Enable all levels by default
ReporterLevel m_enabledLevels = ReporterLevel::All;
};

// Indirection to enable change without tracking down every place
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1064,7 +1064,7 @@ namespace AppInstaller::CLI::Workflow
}

auto promptString = m_isApply ? Resource::String::ConfigurationWarningPromptApply : Resource::String::ConfigurationWarningPromptTest;
if (!context.Reporter.PromptForBoolResponse(promptString, Reporter::Level::Warning))
if (!context.Reporter.PromptForBoolResponse(promptString, ReporterLevel::Warning))
Trenly marked this conversation as resolved.
Show resolved Hide resolved
{
AICLI_TERMINATE_CONTEXT(WINGET_CONFIG_ERROR_WARNING_NOT_ACCEPTED);
}
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCLICore/Workflows/PromptFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -267,7 +267,7 @@ namespace AppInstaller::CLI::Workflow
context.Reporter.Info() << Resource::String::InstallersRequireInstallLocation << std::endl;
for (auto packageContext : packagesToPrompt)
{
*packageContext << ReportManifestIdentityWithVersion(" - "_liv, Execution::Reporter::Level::Warning);
*packageContext << ReportManifestIdentityWithVersion(" - "_liv, Execution::ReporterLevel::Warning);
if (packageContext->IsTerminated())
{
AICLI_TERMINATE_CONTEXT(packageContext->GetTerminationHR());
Expand Down Expand Up @@ -335,7 +335,7 @@ namespace AppInstaller::CLI::Workflow
context.Reporter.Warn() << Resource::String::InstallersAbortTerminal << std::endl;
for (auto packageContext : packagesToPrompt)
{
*packageContext << ReportManifestIdentityWithVersion(" - "_liv, Execution::Reporter::Level::Warning);
*packageContext << ReportManifestIdentityWithVersion(" - "_liv, Execution::ReporterLevel::Warning);
if (packageContext->IsTerminated())
{
AICLI_TERMINATE_CONTEXT(packageContext->GetTerminationHR());
Expand All @@ -354,7 +354,7 @@ namespace AppInstaller::CLI::Workflow
return;
}

bool accepted = context.Reporter.PromptForBoolResponse(Resource::String::PromptToProceed, Execution::Reporter::Level::Warning);
bool accepted = context.Reporter.PromptForBoolResponse(Resource::String::PromptToProceed, Execution::ReporterLevel::Warning);
if (accepted)
{
AICLI_LOG(CLI, Info, << "Proceeding with installation");
Expand Down
2 changes: 1 addition & 1 deletion src/AppInstallerCLICore/Workflows/WorkflowBase.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ namespace AppInstaller::CLI::Workflow
std::string_view name,
std::string_view id,
std::string_view version = {},
Execution::Reporter::Level level = Execution::Reporter::Level::Info)
Execution::ReporterLevel level = Execution::ReporterLevel::Info)
{
auto out = context.Reporter.GetOutputStream(level);
out << prefix;
Expand Down
6 changes: 3 additions & 3 deletions src/AppInstallerCLICore/Workflows/WorkflowBase.h
Original file line number Diff line number Diff line change
Expand Up @@ -365,17 +365,17 @@ namespace AppInstaller::CLI::Workflow
// Outputs: None
struct ReportManifestIdentityWithVersion : public WorkflowTask
{
ReportManifestIdentityWithVersion(Utility::LocIndView prefix, Execution::Reporter::Level level = Execution::Reporter::Level::Info) :
ReportManifestIdentityWithVersion(Utility::LocIndView prefix, Execution::ReporterLevel level = Execution::ReporterLevel::Info) :
WorkflowTask("ReportManifestIdentityWithVersion"), m_prefix(prefix), m_level(level) {}
ReportManifestIdentityWithVersion(Resource::StringId label = Resource::String::ReportIdentityFound, Execution::Reporter::Level level = Execution::Reporter::Level::Info) :
ReportManifestIdentityWithVersion(Resource::StringId label = Resource::String::ReportIdentityFound, Execution::ReporterLevel level = Execution::ReporterLevel::Info) :
WorkflowTask("ReportManifestIdentityWithVersion"), m_label(label), m_level(level) {}

void operator()(Execution::Context& context) const override;

private:
Utility::LocIndView m_prefix;
std::optional<Resource::StringId> m_label;
Execution::Reporter::Level m_level;
Execution::ReporterLevel m_level;
};

// Selects the installer from the manifest, if one is applicable.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -262,7 +262,7 @@ They can be configured through the settings file 'winget settings'.</value>
<value>Filter results by id</value>
</data>
<data name="IgnoreWarningsArgumentDescription" xml:space="preserve">
<value>Suppresses warning outputs.</value>
<value>Suppresses warning outputs</value>
</data>
<data name="InstallationDisclaimer1" xml:space="preserve">
<value>This application is licensed to you by its owner.</value>
Expand Down
Loading