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

Add experimental feature for font list command #4886

Merged
merged 19 commits into from
Oct 28, 2024
Merged
Show file tree
Hide file tree
Changes from 9 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
5 changes: 5 additions & 0 deletions schemas/JSON/settings/settings.schema.0.2.json
Original file line number Diff line number Diff line change
Expand Up @@ -287,6 +287,11 @@
"description": "Enable support for the configure export command",
"type": "boolean",
"default": false
},
"Font": {
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
"description": "Enable support for managing Font",
"type": "boolean",
"default": false
}
}
}
Expand Down
4 changes: 4 additions & 0 deletions src/AppInstallerCLICore/AppInstallerCLICore.vcxproj
Original file line number Diff line number Diff line change
Expand Up @@ -364,6 +364,7 @@
<ClInclude Include="Commands\ErrorCommand.h" />
<ClInclude Include="Commands\ExperimentalCommand.h" />
<ClInclude Include="Commands\ExportCommand.h" />
<ClInclude Include="Commands\FontCommand.h" />
<ClInclude Include="Commands\ImportCommand.h" />
<ClInclude Include="Commands\FeaturesCommand.h" />
<ClInclude Include="Commands\HashCommand.h" />
Expand Down Expand Up @@ -410,6 +411,7 @@
<ClInclude Include="Workflows\CompletionFlow.h" />
<ClInclude Include="Workflows\DependencyNodeProcessor.h" />
<ClInclude Include="Workflows\DownloadFlow.h" />
<ClInclude Include="Workflows\FontFlow.h" />
<ClInclude Include="Workflows\ImportExportFlow.h" />
<ClInclude Include="Workflows\MsiInstallFlow.h" />
<ClInclude Include="Workflows\MSStoreInstallerHandler.h" />
Expand Down Expand Up @@ -441,6 +443,7 @@
<ClCompile Include="Commands\DebugCommand.cpp" />
<ClCompile Include="Commands\DownloadCommand.cpp" />
<ClCompile Include="Commands\ErrorCommand.cpp" />
<ClCompile Include="Commands\FontCommand.cpp" />
<ClCompile Include="Commands\ImportCommand.cpp" />
<ClCompile Include="Commands\PinCommand.cpp" />
<ClCompile Include="Commands\RepairCommand.cpp" />
Expand Down Expand Up @@ -490,6 +493,7 @@
<ClCompile Include="Workflows\CompletionFlow.cpp" />
<ClCompile Include="Workflows\DependencyNodeProcessor.cpp" />
<ClCompile Include="Workflows\DownloadFlow.cpp" />
<ClCompile Include="Workflows\FontFlow.cpp" />
<ClCompile Include="Workflows\ImportExportFlow.cpp" />
<ClCompile Include="Workflows\MsiInstallFlow.cpp" />
<ClCompile Include="Workflows\MSStoreInstallerHandler.cpp" />
Expand Down
12 changes: 12 additions & 0 deletions src/AppInstallerCLICore/AppInstallerCLICore.vcxproj.filters
Original file line number Diff line number Diff line change
Expand Up @@ -260,6 +260,12 @@
<ClInclude Include="Sixel.h">
<Filter>Header Files</Filter>
</ClInclude>
<ClInclude Include="Commands\FontCommand.h">
<Filter>Commands</Filter>
</ClInclude>
<ClInclude Include="Workflows\FontFlow.h">
<Filter>Workflows</Filter>
</ClInclude>
</ItemGroup>
<ItemGroup>
<ClCompile Include="pch.cpp">
Expand Down Expand Up @@ -490,6 +496,12 @@
<ClCompile Include="Sixel.cpp">
<Filter>Source Files</Filter>
</ClCompile>
<ClCompile Include="Commands\FontCommand.cpp">
<Filter>Commands</Filter>
</ClCompile>
<ClCompile Include="Workflows\FontFlow.cpp">
<Filter>Workflows</Filter>
</ClCompile>
</ItemGroup>
<ItemGroup>
<None Include="PropertySheet.props" />
Expand Down
6 changes: 6 additions & 0 deletions src/AppInstallerCLICore/Argument.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -198,6 +198,10 @@ namespace AppInstaller::CLI
case Execution::Args::Type::IgnoreResumeLimit:
return { type, "ignore-resume-limit"_liv, ArgTypeCategory::None };

// Font command
case Execution::Args::Type::FamilyName:
return { type, "family-name"_liv, ArgTypeCategory::None };
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved

// Configuration commands
case Execution::Args::Type::ConfigurationFile:
return { type, "file"_liv, 'f', ArgTypeCategory::ConfigurationSetChoice, ArgTypeExclusiveSet::ConfigurationSetChoice };
Expand Down Expand Up @@ -430,6 +434,8 @@ namespace AppInstaller::CLI
return Argument{ type, Resource::String::ProxyArgumentDescription, ArgumentType::Standard, TogglePolicy::Policy::ProxyCommandLineOptions, BoolAdminSetting::ProxyCommandLineOptions };
case Args::Type::NoProxy:
return Argument{ type, Resource::String::NoProxyArgumentDescription, ArgumentType::Flag, TogglePolicy::Policy::ProxyCommandLineOptions, BoolAdminSetting::ProxyCommandLineOptions };
case Args::Type::FamilyName:
return Argument{ type, Resource::String::FontFamilyNameArgumentDescription, ArgumentType::Standard, false };
default:
THROW_HR(E_UNEXPECTED);
}
Expand Down
86 changes: 86 additions & 0 deletions src/AppInstallerCLICore/Commands/FontCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,86 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "FontCommand.h"
#include "Workflows/CompletionFlow.h"
#include "Workflows/WorkflowBase.h"
#include "Workflows/FontFlow.h"
#include "Resources.h"

namespace AppInstaller::CLI
{
using namespace AppInstaller::CLI::Execution;
using namespace AppInstaller::CLI::Workflow;
using namespace AppInstaller::Utility::literals;
using namespace std::string_view_literals;

Utility::LocIndView s_FontCommand_HelpLink = "https://aka.ms/winget-command-help"_liv;
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved

std::vector<std::unique_ptr<Command>> FontCommand::GetCommands() const
{
return InitializeFromMoveOnly<std::vector<std::unique_ptr<Command>>>({
std::make_unique<FontListCommand>(FullName()),
});
}

Resource::LocString FontCommand::ShortDescription() const
{
return { Resource::String::FontCommandShortDescription };
}

Resource::LocString FontCommand::LongDescription() const
{
return { Resource::String::FontCommandLongDescription };
}

Utility::LocIndView FontCommand::HelpLink() const
{
return s_FontCommand_HelpLink;
}

void FontCommand::ExecuteInternal(Execution::Context& context) const
{
OutputHelp(context.Reporter);
}

std::vector<Argument> FontListCommand::GetArguments() const
{
return {
Argument::ForType(Args::Type::FamilyName),
Argument::ForType(Args::Type::Moniker),
Argument::ForType(Args::Type::Source),
Argument::ForType(Args::Type::Tag),
Argument::ForType(Args::Type::Exact),
Argument::ForType(Args::Type::AuthenticationMode),
Argument::ForType(Args::Type::AuthenticationAccount),
Argument::ForType(Args::Type::AcceptSourceAgreements),
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
};
}

Resource::LocString FontListCommand::ShortDescription() const
{
return { Resource::String::FontListCommandShortDescription };
}

Resource::LocString FontListCommand::LongDescription() const
{
return { Resource::String::FontListCommandLongDescription };
}

void FontListCommand::Complete(Execution::Context& context, Args::Type valueType) const
{
UNREFERENCED_PARAMETER(valueType);
context.Reporter.Error() << Resource::String::PendingWorkError << std::endl;
THROW_HR(E_NOTIMPL);
}

Utility::LocIndView FontListCommand::HelpLink() const
{
return s_FontCommand_HelpLink;
}

void FontListCommand::ExecuteInternal(Execution::Context& context) const
{
context << Workflow::ReportInstalledFontsResult;
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
}
}
40 changes: 40 additions & 0 deletions src/AppInstallerCLICore/Commands/FontCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,40 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#pragma once
#include "Command.h"
#include <winget/UserSettings.h>

namespace AppInstaller::CLI
{
struct FontCommand final : public Command
{
FontCommand(std::string_view parent) : Command("font", {} /* aliases */, parent, Settings::ExperimentalFeature::Feature::Font) {}

std::vector<std::unique_ptr<Command>> GetCommands() const override;

Resource::LocString ShortDescription() const override;
Resource::LocString LongDescription() const override;

Utility::LocIndView HelpLink() const override;

protected:
void ExecuteInternal(Execution::Context& context) const override;
};

struct FontListCommand final : public Command
{
FontListCommand(std::string_view parent) : Command("list", parent) {}

std::vector<Argument> GetArguments() const override;

Resource::LocString ShortDescription() const override;
Resource::LocString LongDescription() const override;

void Complete(Execution::Context& context, Execution::Args::Type valueType) const override;

Utility::LocIndView HelpLink() const override;

protected:
void ExecuteInternal(Execution::Context& context) const override;
};
}
2 changes: 2 additions & 0 deletions src/AppInstallerCLICore/Commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include "ValidateCommand.h"
#include "SettingsCommand.h"
#include "FeaturesCommand.h"
#include "FontCommand.h"
#include "ExperimentalCommand.h"
#include "CompleteCommand.h"
#include "ExportCommand.h"
Expand Down Expand Up @@ -194,6 +195,7 @@ namespace AppInstaller::CLI
std::make_unique<ErrorCommand>(FullName()),
std::make_unique<ResumeCommand>(FullName()),
std::make_unique<RepairCommand>(FullName()),
std::make_unique<FontCommand>(FullName()),
#if _DEBUG
std::make_unique<DebugCommand>(FullName()),
#endif
Expand Down
3 changes: 3 additions & 0 deletions src/AppInstallerCLICore/ExecutionArgs.h
Original file line number Diff line number Diff line change
Expand Up @@ -121,6 +121,9 @@ namespace AppInstaller::CLI::Execution
ResumeId,
IgnoreResumeLimit,

// Font Command
FamilyName,

// Configuration
ConfigurationFile,
ConfigurationAcceptWarning,
Expand Down
10 changes: 10 additions & 0 deletions src/AppInstallerCLICore/Resources.h
Original file line number Diff line number Diff line change
Expand Up @@ -248,6 +248,15 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(FileNotFound);
WINGET_DEFINE_RESOURCE_STRINGID(FilesRemainInInstallDirectory);
WINGET_DEFINE_RESOURCE_STRINGID(FlagContainAdjoinedError);
WINGET_DEFINE_RESOURCE_STRINGID(FontCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(FontCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(FontFaceCount);
WINGET_DEFINE_RESOURCE_STRINGID(FontFace);
WINGET_DEFINE_RESOURCE_STRINGID(FontFamily);
WINGET_DEFINE_RESOURCE_STRINGID(FontFamilyNameArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(FontFilePaths);
WINGET_DEFINE_RESOURCE_STRINGID(FontListCommandLongDescription);
WINGET_DEFINE_RESOURCE_STRINGID(FontListCommandShortDescription);
WINGET_DEFINE_RESOURCE_STRINGID(ForceArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(GatedVersionArgumentDescription);
WINGET_DEFINE_RESOURCE_STRINGID(GetManifestResultVersionNotFound);
Expand Down Expand Up @@ -403,6 +412,7 @@ namespace AppInstaller::CLI::Resource
WINGET_DEFINE_RESOURCE_STRINGID(NoAdminRepairForUserScopePackage);
WINGET_DEFINE_RESOURCE_STRINGID(NoApplicableInstallers);
WINGET_DEFINE_RESOURCE_STRINGID(NoExperimentalFeaturesMessage);
WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledFontFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoInstalledPackageFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackageFound);
WINGET_DEFINE_RESOURCE_STRINGID(NoPackageSelectionArgumentProvided);
Expand Down
118 changes: 118 additions & 0 deletions src/AppInstallerCLICore/Workflows/FontFlow.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,118 @@
// Copyright (c) Microsoft Corporation.
// Licensed under the MIT License.
#include "pch.h"
#include "FontFlow.h"
#include "TableOutput.h"
#include <winget/Fonts.h>

namespace AppInstaller::CLI::Workflow
{
using namespace AppInstaller::CLI::Execution;

namespace
{
struct InstalledFontFamiliesTableLine
{
InstalledFontFamiliesTableLine(Utility::LocIndString familyName, int faceCount)
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
: FamilyName(familyName), FaceCount(faceCount) {}

Utility::LocIndString FamilyName;
int FaceCount;
};

struct InstalledFontFacesTableLine
{
InstalledFontFacesTableLine(Utility::LocIndString faceName, Utility::LocIndString familyName, std::filesystem::path filePath)
: FaceName(faceName), FamilyName(familyName), FilePath(filePath) {}

Utility::LocIndString FaceName;
Utility::LocIndString FamilyName;
std::filesystem::path FilePath;
};

void OutputInstalledFontFamiliesTable(Execution::Context& context, const std::vector<InstalledFontFamiliesTableLine>& lines)
{
Execution::TableOutput<2> table(context.Reporter, { Resource::String::FontFamily, Resource::String::FontFaceCount });

for (const auto& line : lines)
{
table.OutputLine({ line.FamilyName, std::to_string(line.FaceCount) });
}

table.Complete();
}

void OutputInstalledFontFacesTable(Execution::Context& context, const std::vector<InstalledFontFacesTableLine>& lines)
{
Execution::TableOutput<3> table(context.Reporter, { Resource::String::FontFace, Resource::String::FontFamily, Resource::String::FontFilePaths });

for (const auto& line : lines)
{
table.OutputLine({ line.FaceName, line.FamilyName, line.FilePath.u8string() });
}

table.Complete();
}
}

void ReportInstalledFontsResult(Execution::Context& context)
{
if (context.Args.Contains(Args::Type::FamilyName))
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will there be any provision for searching by Face Name? Not sure if it provides value or not

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yup, will come out in a later PR when I implement a searchable font source.

{
// TODO: Utilize font index for better searching capabitility.

Check failure on line 62 in src/AppInstallerCLICore/Workflows/FontFlow.cpp

View workflow job for this annotation

GitHub Actions / Check Spelling

`capabitility` is not a recognized word. (unrecognized-spelling)
const auto& familyNameArg = context.Args.GetArg(Args::Type::FamilyName);
const auto& fontFamily = AppInstaller::Fonts::GetInstalledFontFamily(AppInstaller::Utility::ConvertToUTF16(familyNameArg));

if (!fontFamily.has_value())
{
context.Reporter.Info() << Resource::String::NoInstalledFontFound << std::endl;
return;
}

const auto& familyName = Utility::LocIndString(Utility::ConvertToUTF8(fontFamily->Name));
std::vector<InstalledFontFacesTableLine> lines;

for (const auto& fontFace : fontFamily->Faces)
{
bool isFirstLine = true;
for (const auto& filePath : fontFace.FilePaths)
{
if (isFirstLine)
ryfu-msft marked this conversation as resolved.
Show resolved Hide resolved
{
InstalledFontFacesTableLine line(
Utility::LocIndString(Utility::ToLower(Utility::ConvertToUTF8(fontFace.Name))),
familyName,
filePath.u8string()
);
isFirstLine = false;
lines.push_back(std::move(line));
}
else
{
InstalledFontFacesTableLine line({}, {}, filePath.u8string());
lines.push_back(std::move(line));
}
}
}

OutputInstalledFontFacesTable(context, lines);
}
else
{
const auto& fontFamilies = AppInstaller::Fonts::GetInstalledFontFamilies();
std::vector<InstalledFontFamiliesTableLine> lines;

for (const auto& fontFamily : fontFamilies)
{
InstalledFontFamiliesTableLine line(
Utility::LocIndString(Utility::ConvertToUTF8(fontFamily.Name)),
static_cast<int>(fontFamily.Faces.size())
);

lines.push_back(std::move(line));
}

OutputInstalledFontFamiliesTable(context, lines);
}
}
}
Loading
Loading