Skip to content

Commit

Permalink
Allow for smaller configuration outputs (microsoft#4754)
Browse files Browse the repository at this point in the history
## 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.
  • Loading branch information
JohnMcPMS authored Sep 3, 2024
1 parent 3c53030 commit 43686bb
Show file tree
Hide file tree
Showing 7 changed files with 42 additions and 20 deletions.
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Commands/ConfigureCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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 },
};
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -124,6 +124,7 @@ namespace AppInstaller::CLI::Execution
// Configuration
ConfigurationFile,
ConfigurationAcceptWarning,
ConfigurationSuppressPrologue,
ConfigurationEnable,
ConfigurationDisable,
ConfigurationModulePath,
Expand Down
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
47 changes: 27 additions & 20 deletions src/AppInstallerCLICore/Workflows/ConfigurationFlow.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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)
Expand All @@ -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)
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLIPackage/Shared/Strings/en-us/winget.resw
Original file line number Diff line number Diff line change
Expand Up @@ -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>
7 changes: 7 additions & 0 deletions src/ConfigurationRemotingServer/Program.cs
Original file line number Diff line number Diff line change
Expand Up @@ -70,6 +70,9 @@ internal class Program

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;

Expand Down Expand Up @@ -196,5 +199,9 @@ private static extern int WindowsPackageManagerConfigurationCompleteOutOfProcess

[DllImport("kernel32.dll", CharSet = CharSet.Unicode)]
private static extern IntPtr GetCommandLineW();

[DllImport("kernel32.dll")]
[return: MarshalAs(UnmanagedType.Bool)]
private static extern bool FreeConsole();
}
}

0 comments on commit 43686bb

Please sign in to comment.