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
4 changes: 4 additions & 0 deletions src/AppInstallerCLICore/ChannelStreams.h
Original file line number Diff line number Diff line change
Expand Up @@ -94,6 +94,10 @@ namespace AppInstaller::CLI::Execution
OutputStream& operator<<(const VirtualTerminal::ConstructedSequence& sequence);
OutputStream& operator<<(const std::filesystem::path& path);

inline bool IsEnabled() {
return m_enabled;
}

private:
// Applies the format for the stream.
void ApplyFormat();
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.SetLevelMask(Execution::Reporter::Level::Warning, false);
}

context.UpdateForArgs();
context.SetExecutingCommand(command.get());
command->ValidateArguments(context.Args);
Expand Down
40 changes: 37 additions & 3 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 (WI_AreAllFlagsClear(m_enabledLevels, level))
{
return OutputStream(*m_out, false, false);
}

OutputStream result = GetBasicOutputStream();

switch (level)
Expand Down Expand Up @@ -111,15 +117,21 @@ namespace AppInstaller::CLI::Execution
}
}

bool Reporter::PromptForBoolResponse(Resource::LocString message, Level level)
bool Reporter::PromptForBoolResponse(Resource::LocString message, Level level, bool resultIfDisabled)
{
auto out = GetOutputStream(level);

if (!out.IsEnabled())
{
return resultIfDisabled;
}

const std::vector<BoolPromptOption> options
{
BoolPromptOption{ Resource::String::PromptOptionYes, 'Y', true },
BoolPromptOption{ Resource::String::PromptOptionNo, 'N', false },
};

auto out = GetOutputStream(level);
out << message << std::endl;

// Try prompting until we get a recognized option
Expand Down Expand Up @@ -164,14 +176,24 @@ namespace AppInstaller::CLI::Execution
void Reporter::PromptForEnter(Level level)
{
auto out = GetOutputStream(level);
if (!out.IsEnabled())
{
return;
}

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, Level level, std::filesystem::path resultIfDisabled)
{
auto out = GetOutputStream(level);

if (!out.IsEnabled())
{
return resultIfDisabled;
}

// Try prompting until we get a valid answer
for (;;)
{
Expand Down Expand Up @@ -319,4 +341,16 @@ namespace AppInstaller::CLI::Execution
}
m_out->RestoreDefault();
}

void Reporter::SetLevelMask(Level reporterLevel, bool setEnabled) {

if (setEnabled)
{
WI_SetAllFlags(m_enabledLevels, reporterLevel);
}
else
{
WI_ClearAllFlags(m_enabledLevels, reporterLevel);
}
}
}
29 changes: 21 additions & 8 deletions src/AppInstallerCLICore/ExecutionReporter.h
Original file line number Diff line number Diff line change
Expand Up @@ -49,12 +49,14 @@ namespace AppInstaller::CLI::Execution
};

// The level for the Output channel.
enum class Level
enum class Level : uint32_t
{
Verbose,
Info,
Warning,
Error,
None = 0x0,
Verbose = 0x1,
Info = 0x2,
Warning = 0x4,
Error = 0x8,
All = Verbose | Info | Warning | Error,
};

Reporter(std::ostream& outStream, std::istream& inStream);
Expand Down Expand Up @@ -98,13 +100,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, Level level = Level::Info, bool resultIfDisabled = false);

// Prompts the user, continues when Enter is pressed
void PromptForEnter(Level level = Level::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, Level level = Level::Info, std::filesystem::path resultIfDisabled = std::filesystem::path::path());

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

bool IsLevelEnabled(Level reporterLevel)
{
return WI_AreAllFlagsSet(m_enabledLevels, reporterLevel);
}

void SetLevelMask(Level reporterLevel, bool setEnabled = true);

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

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

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

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

DEFINE_ENUM_FLAG_OPERATORS(Reporter::Level);

// Indirection to enable change without tracking down every place
extern const VirtualTerminal::Sequence& HelpCommandEmphasis;
extern const VirtualTerminal::Sequence& HelpArgumentEmphasis;
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, Reporter::Level::Warning, true))
Trenly marked this conversation as resolved.
Show resolved Hide resolved
{
AICLI_TERMINATE_CONTEXT(WINGET_CONFIG_ERROR_WARNING_NOT_ACCEPTED);
}
Expand Down
7 changes: 6 additions & 1 deletion src/AppInstallerCLICore/Workflows/PromptFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
#include "ShowFlow.h"
#include <winget/UserSettings.h>

using namespace AppInstaller::CLI::Execution;
using namespace AppInstaller::Settings;
using namespace AppInstaller::Utility::literals;

Expand Down Expand Up @@ -295,6 +296,10 @@ namespace AppInstaller::CLI::Workflow

AICLI_LOG(CLI, Info, << "Prompting for install root.");
m_installLocation = context.Reporter.PromptForPath(Resource::String::PromptForInstallRoot);
if (m_installLocation.empty())
{
Trenly marked this conversation as resolved.
Show resolved Hide resolved
AICLI_TERMINATE_CONTEXT(APPINSTALLER_CLI_ERROR_INSTALL_LOCATION_REQUIRED);
}
AICLI_LOG(CLI, Info, << "Proceeding with installation using install root: " << m_installLocation);
}

Expand Down Expand Up @@ -354,7 +359,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, Reporter::Level::Warning, true);
if (accepted)
{
AICLI_LOG(CLI, Info, << "Proceeding with installation");
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