commit 43686bbe75eb257ccba95cc9e47f713691ee1da9
parent 3c530305b32e06b1610009a0312f7b73899086b4
Author: JohnMcPMS <johnmcp@microsoft.com>
Date: Tue, 3 Sep 2024 14:38:59 -0700
Allow for smaller configuration outputs (#4754)
## Change
To prevent anything from outputting to our console, call `FreeConsole`
in the configuration server.
To allow for output of primarily results, when
`--accept-configuration-agreements` is passed, one can now also pass
`--suppress-prologue` to prevent the initial details from being
presented. The only output (beyond the temporary progress spinner+text)
will then be the disclaimer warning and the individual results.
Diffstat:
7 files changed, 42 insertions(+), 20 deletions(-)
diff --git a/src/AppInstallerCLICore/Argument.cpp b/src/AppInstallerCLICore/Argument.cpp
@@ -203,6 +203,8 @@ namespace AppInstaller::CLI
return { type, "file"_liv, 'f', ArgTypeCategory::ConfigurationSetChoice, ArgTypeExclusiveSet::ConfigurationSetChoice };
case Execution::Args::Type::ConfigurationAcceptWarning:
return { type, "accept-configuration-agreements"_liv };
+ case Execution::Args::Type::ConfigurationSuppressPrologue:
+ return { type, "suppress-initial-details"_liv };
case Execution::Args::Type::ConfigurationEnable:
return { type, "enable"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::StubType };
case Execution::Args::Type::ConfigurationDisable:
diff --git a/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp b/src/AppInstallerCLICore/Commands/ConfigureCommand.cpp
@@ -39,6 +39,7 @@ namespace AppInstaller::CLI
Argument{ Execution::Args::Type::ConfigurationModulePath, Resource::String::ConfigurationModulePath, ArgumentType::Positional },
Argument{ Execution::Args::Type::ConfigurationHistoryItem, Resource::String::ConfigurationHistoryItemArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help },
Argument{ Execution::Args::Type::ConfigurationAcceptWarning, Resource::String::ConfigurationAcceptWarningArgumentDescription, ArgumentType::Flag },
+ Argument{ Execution::Args::Type::ConfigurationSuppressPrologue, Resource::String::ConfigurationSuppressPrologueArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help },
Argument{ Execution::Args::Type::ConfigurationEnable, Resource::String::ConfigurationEnableMessage, ArgumentType::Flag, Argument::Visibility::Help },
Argument{ Execution::Args::Type::ConfigurationDisable, Resource::String::ConfigurationDisableMessage, ArgumentType::Flag, Argument::Visibility::Help },
};
diff --git a/src/AppInstallerCLICore/ExecutionArgs.h b/src/AppInstallerCLICore/ExecutionArgs.h
@@ -124,6 +124,7 @@ namespace AppInstaller::CLI::Execution
// Configuration
ConfigurationFile,
ConfigurationAcceptWarning,
+ ConfigurationSuppressPrologue,
ConfigurationEnable,
ConfigurationDisable,
ConfigurationModulePath,
diff --git a/src/AppInstallerCLICore/Resources.h b/src/AppInstallerCLICore/Resources.h
@@ -106,6 +106,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSettings);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationStatusWatchArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSuccessfullyApplied);
+ WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationSuppressPrologueArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnexpectedTestResult);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitAssertHadNegativeResult);
WINGET_DEFINE_RESOURCE_STRINGID(ConfigurationUnitFailed);
diff --git a/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp b/src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
@@ -1369,27 +1369,31 @@ namespace AppInstaller::CLI::Workflow
auto getDetailsOperation = configContext.Processor().GetSetDetailsAsync(configContext.Set(), ConfigurationUnitDetailFlags::ReadOnly);
auto unification = anon::CreateProgressCancellationUnification(std::move(progressScope), getDetailsOperation);
+ bool suppressDetailsOutput = context.Args.Contains(Args::Type::ConfigurationAcceptWarning) && context.Args.Contains(Args::Type::ConfigurationSuppressPrologue);
anon::OutputHelper outputHelper{ context };
uint32_t unitsShown = 0;
- getDetailsOperation.Progress([&](const IAsyncOperationWithProgress<GetConfigurationSetDetailsResult, GetConfigurationUnitDetailsResult>& operation, const GetConfigurationUnitDetailsResult&)
- {
- auto threadContext = context.SetForCurrentThread();
+ if (!suppressDetailsOutput)
+ {
+ getDetailsOperation.Progress([&](const IAsyncOperationWithProgress<GetConfigurationSetDetailsResult, GetConfigurationUnitDetailsResult>& operation, const GetConfigurationUnitDetailsResult&)
+ {
+ auto threadContext = context.SetForCurrentThread();
- unification.Reset();
+ unification.Reset();
- auto unitResults = operation.GetResults().UnitResults();
- for (unitsShown; unitsShown < unitResults.Size(); ++unitsShown)
- {
- GetConfigurationUnitDetailsResult unitResult = unitResults.GetAt(unitsShown);
- anon::LogFailedGetConfigurationUnitDetails(unitResult.Unit(), unitResult.ResultInformation());
- outputHelper.OutputConfigurationUnitInformation(unitResult.Unit());
- }
+ auto unitResults = operation.GetResults().UnitResults();
+ for (unitsShown; unitsShown < unitResults.Size(); ++unitsShown)
+ {
+ GetConfigurationUnitDetailsResult unitResult = unitResults.GetAt(unitsShown);
+ anon::LogFailedGetConfigurationUnitDetails(unitResult.Unit(), unitResult.ResultInformation());
+ outputHelper.OutputConfigurationUnitInformation(unitResult.Unit());
+ }
- progressScope = context.Reporter.BeginAsyncProgress(true);
- progressScope->Callback().SetProgressMessage(gettingDetailString);
- unification.Progress(std::move(progressScope));
- });
+ progressScope = context.Reporter.BeginAsyncProgress(true);
+ progressScope->Callback().SetProgressMessage(gettingDetailString);
+ unification.Progress(std::move(progressScope));
+ });
+ }
HRESULT hr = S_OK;
GetConfigurationSetDetailsResult result = nullptr;
@@ -1419,7 +1423,7 @@ namespace AppInstaller::CLI::Workflow
}
// Handle any missing progress callbacks that are in the results
- if (result)
+ if (result && !suppressDetailsOutput)
{
auto unitResults = result.UnitResults();
if (unitResults)
@@ -1434,11 +1438,14 @@ namespace AppInstaller::CLI::Workflow
}
// Handle any units that are NOT in the results (due to an exception part of the way through)
- auto allUnits = configContext.Set().Units();
- for (unitsShown; unitsShown < allUnits.Size(); ++unitsShown)
+ if (!suppressDetailsOutput)
{
- ConfigurationUnit unit = allUnits.GetAt(unitsShown);
- outputHelper.OutputConfigurationUnitInformation(unit);
+ auto allUnits = configContext.Set().Units();
+ for (unitsShown; unitsShown < allUnits.Size(); ++unitsShown)
+ {
+ ConfigurationUnit unit = allUnits.GetAt(unitsShown);
+ outputHelper.OutputConfigurationUnitInformation(unit);
+ }
}
if (outputHelper.ValuesTruncated)
diff --git a/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw b/src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
@@ -3109,4 +3109,7 @@ Please specify one of them using the --source option to proceed.</value>
<data name="StoreInstall_PackageNotAvailableForCurrentSystem" xml:space="preserve">
<value>The package is not compatible with the current Windows version or platform.</value>
</data>
+ <data name="ConfigurationSuppressPrologueArgumentDescription" xml:space="preserve">
+ <value>Suppress showing initial configuration details when possible</value>
+ </data>
</root>
\ No newline at end of file
diff --git a/src/ConfigurationRemotingServer/Program.cs b/src/ConfigurationRemotingServer/Program.cs
@@ -70,6 +70,9 @@ namespace ConfigurationRemotingServer
static int Main(string[] args)
{
+ // Remove any attached console to prevent modules (or their actions) from writing to our console.
+ FreeConsole();
+
// Help find WindowsPackageManager.dll
AssemblyLoadContext.Default.ResolvingUnmanagedDll += NativeAssemblyLoadContext.ResolvingUnmanagedHandler;
@@ -196,5 +199,9 @@ namespace ConfigurationRemotingServer
[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr GetCommandLineW();
+
+ [DllImport("kernel32.dll")]
+ [return: MarshalAs(UnmanagedType.Bool)]
+ private static extern bool FreeConsole();
}
}