Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion doc/ReleaseNotes.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
## New in v1.29

Nothing yet.
* Added `--format json` support for `winget list` and `winget upgrade` when listing available upgrades.

## Bug Fixes

Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -195,6 +195,8 @@ namespace AppInstaller::CLI
return { type, "ascending"_liv, "asc"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::SortDirection };
case Execution::Args::Type::SortDescending:
return { type, "descending"_liv, "desc"_liv, ArgTypeCategory::None, ArgTypeExclusiveSet::SortDirection };
case Execution::Args::Type::OutputFormat:
return { type, "format"_liv };

// Pin command
case Execution::Args::Type::GatedVersion:
Expand Down Expand Up @@ -508,6 +510,8 @@ namespace AppInstaller::CLI
return Argument{ type, Resource::String::CorrelationArgumentDescription, ArgumentType::Standard, Argument::Visibility::Hidden };
case Args::Type::ListDetails:
return Argument{ type, Resource::String::ListDetailsArgumentDescription, ArgumentType::Flag, Argument::Visibility::Help };
case Args::Type::OutputFormat:
return Argument{ type, Resource::String::OutputFormatArgumentDescription, ArgumentType::Standard, Argument::Visibility::Help };
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down
17 changes: 17 additions & 0 deletions src/AppInstallerCLICore/Command.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@
#include "Command.h"
#include "Resources.h"
#include "Sixel.h"
#include "Workflows/WorkflowBase.h"
#include <winget/UserSettings.h>
#include <AppInstallerRuntime.h>
#include <winget/Locale.h>
Expand Down Expand Up @@ -819,6 +820,17 @@ namespace AppInstaller::CLI
}
}

if (execArgs.Contains(Execution::Args::Type::OutputFormat))
{
auto format = execArgs.GetArg(Execution::Args::Type::OutputFormat);
if (!Utility::CaseInsensitiveEquals(format, "table"sv) &&
!Utility::CaseInsensitiveEquals(format, "json"sv))
{
auto validOptions = Utility::Join(", "_liv, std::vector<Utility::LocIndString>{ "table"_lis, "json"_lis });
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::OutputFormat).Name, validOptions));
}
}

Argument::ValidateExclusiveArguments(execArgs);

ValidateArgumentsInternal(execArgs);
Expand Down Expand Up @@ -1060,6 +1072,11 @@ namespace AppInstaller::CLI
{
try
{
if (!context.Args.Contains(Execution::Args::Type::Help))
{
Workflow::SetJsonOutputChannel(context);
}

if (!Settings::User().GetWarnings().empty() &&
!WI_IsFlagSet(command->GetOutputFlags(), CommandOutputFlags::IgnoreSettingsWarnings))
{
Expand Down
9 changes: 9 additions & 0 deletions src/AppInstallerCLICore/Commands/ListCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -9,6 +9,7 @@
namespace AppInstaller::CLI
{
using namespace AppInstaller::CLI::Workflow;
using namespace AppInstaller::Utility::literals;
using namespace std::string_view_literals;

std::vector<Argument> ListCommand::GetArguments() const
Expand All @@ -35,6 +36,7 @@ namespace AppInstaller::CLI
Argument{ Execution::Args::Type::IncludeUnknown, Resource::String::IncludeUnknownInListArgumentDescription, ArgumentType::Flag },
Argument{ Execution::Args::Type::IncludePinned, Resource::String::IncludePinnedInListArgumentDescription, ArgumentType::Flag},
Argument::ForType(Execution::Args::Type::ListDetails),
Argument::ForType(Execution::Args::Type::OutputFormat),
Argument{ Execution::Args::Type::Sort, Resource::String::SortArgumentDescription, ArgumentType::Standard }.SetCountLimit(s_sortFieldCount),
Argument{ Execution::Args::Type::SortAscending, Resource::String::SortAscendingArgumentDescription, ArgumentType::Flag },
Argument{ Execution::Args::Type::SortDescending, Resource::String::SortDescendingArgumentDescription, ArgumentType::Flag },
Expand Down Expand Up @@ -86,13 +88,20 @@ namespace AppInstaller::CLI
{
Argument::ValidateArgumentDependency(execArgs, Execution::Args::Type::IncludeUnknown, Execution::Args::Type::Upgrade);
Argument::ValidateArgumentDependency(execArgs, Execution::Args::Type::IncludePinned, Execution::Args::Type::Upgrade);

if (Workflow::IsJsonOutputFormat(execArgs) && execArgs.Contains(Execution::Args::Type::ListDetails))
{
auto validOptions = Utility::Join(", "_liv, std::vector<Utility::LocIndString>{ "table"_lis });
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::OutputFormat).Name, validOptions));
}
}

void ListCommand::ExecuteInternal(Execution::Context& context) const
{
context.SetFlags(Execution::ContextFlag::TreatSourceFailuresAsWarning);

context <<
Workflow::SetJsonOutputChannel <<
Workflow::OpenSource() <<
Workflow::OpenCompositeSource(Workflow::DetermineInstalledSource(context)) <<
Workflow::SearchSourceForMany <<
Expand Down
8 changes: 8 additions & 0 deletions src/AppInstallerCLICore/Commands/UpgradeCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace AppInstaller::CLI
Argument::ForType(Args::Type::CustomHeader),
Argument::ForType(Args::Type::AuthenticationMode),
Argument::ForType(Args::Type::AuthenticationAccount),
Argument::ForType(Args::Type::OutputFormat),
Argument{ Args::Type::All, Resource::String::UpdateAllArgumentDescription, ArgumentType::Flag },
Argument{ Args::Type::IncludeUnknown, Resource::String::IncludeUnknownArgumentDescription, ArgumentType::Flag },
Argument{ Args::Type::IncludePinned, Resource::String::IncludePinnedArgumentDescription, ArgumentType::Flag},
Expand Down Expand Up @@ -138,6 +139,12 @@ namespace AppInstaller::CLI
{
const auto argCategories = Argument::GetCategoriesAndValidateCommonArguments(execArgs, /* requirePackageSelectionArg */ false);

if (Workflow::IsJsonOutputFormat(execArgs) && !ShouldListUpgrade(execArgs, argCategories))
{
auto validOptions = Utility::Join(", "_liv, std::vector<Utility::LocIndString>{ "table"_lis });
throw CommandException(Resource::String::InvalidArgumentValueError(ArgumentCommon::ForType(Execution::Args::Type::OutputFormat).Name, validOptions));
}

if (!ShouldListUpgrade(execArgs, argCategories) &&
WI_IsFlagClear(argCategories, ArgTypeCategory::PackageQuery) &&
WI_IsFlagSet(argCategories, ArgTypeCategory::SingleInstallerBehavior))
Expand All @@ -160,6 +167,7 @@ namespace AppInstaller::CLI
context <<
InitializeInstallerDownloadAuthenticatorsMap <<
ReportExecutionStage(ExecutionStage::Discovery) <<
SetJsonOutputChannel <<
OpenSource() <<
OpenCompositeSource(DetermineInstalledSource(context));

Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -196,6 +196,9 @@ namespace AppInstaller::CLI::Execution
// Used for demonstration purposes
ExperimentalArg,

// Output format selector. Keep new arguments appended to preserve serialized argument ordinals.
OutputFormat,

// This should always be at the end
Max
};
Expand Down
7 changes: 7 additions & 0 deletions src/AppInstallerCLICore/ExecutionContextData.h
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,7 @@ namespace AppInstaller::CLI::Execution
RepairString,
MsixDigests,
InstallerDownloadAuthenticators,
SourceOpenUpdateFailures,
Max
};

Expand Down Expand Up @@ -299,5 +300,11 @@ namespace AppInstaller::CLI::Execution
// The authenticator map shared with sub contexts
using value_t = std::shared_ptr<std::map<Authentication::AuthenticationInfo, Authentication::Authenticator>>;
};

template<>
struct DataMapping<Data::SourceOpenUpdateFailures>
{
using value_t = std::vector<Repository::SourceDetails>;
};
}
}
1 change: 1 addition & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -521,6 +521,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(Options);
WINGET_DEFINE_RESOURCE_STRINGID(OSVersionDescription);
WINGET_DEFINE_RESOURCE_STRINGID(OutputDirectoryArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(OutputFormatArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(OutputFileArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(OverrideArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(OverwritingExistingFileAtMessage);
Expand Down
Loading
Loading