Skip to content

Commit 51dc5f8

Browse files
authored
CLI: Table Output updates (#14534)
1 parent 713fcda commit 51dc5f8

18 files changed

Lines changed: 521 additions & 146 deletions

src/windows/common/string.cpp

Lines changed: 11 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -284,4 +284,14 @@ std::string wsl::windows::common::string::WideToMultiByte(_In_opt_ LPCWSTR Sourc
284284
std::string wsl::windows::common::string::WideToMultiByte(_In_ std::wstring_view Source)
285285
{
286286
return WideToMultiByte(Source.data(), Source.length());
287-
}
287+
}
288+
289+
std::wstring wsl::windows::common::string::TruncateId(_In_ std::wstring_view id, bool shortenLength)
290+
{
291+
return TruncateIdImpl(id, shortenLength);
292+
}
293+
294+
std::string wsl::windows::common::string::TruncateId(_In_ std::string_view id, bool shortenLength)
295+
{
296+
return TruncateIdImpl(id, shortenLength);
297+
}

src/windows/common/string.hpp

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,33 @@ std::string WideToMultiByte(_In_opt_ LPCWSTR Source, _In_ size_t CharacterCount
4848

4949
std::string WideToMultiByte(_In_ std::wstring_view Source);
5050

51+
std::wstring TruncateId(_In_ std::wstring_view id, bool shortenLength = true);
52+
std::string TruncateId(_In_ std::string_view id, bool shortenLength = true);
53+
54+
// Template implementation for TruncateId to avoid code duplication.
55+
// Algorithm inspired from Moby for consistency in presentation of shortened IDs.
56+
// Always strips the algorithm prefix (e.g., "sha256:") if present, and optionally shortens to 12 characters.
57+
template <typename TChar>
58+
inline std::basic_string<TChar> TruncateIdImpl(std::basic_string_view<TChar> id, bool shortenLength)
59+
{
60+
constexpr size_t shortLen = 12;
61+
constexpr TChar colon = TChar(':');
62+
63+
// Find and skip algorithm prefix if present (e.g., "sha256:")
64+
auto colonPos = id.find(colon);
65+
if (colonPos != std::basic_string_view<TChar>::npos)
66+
{
67+
id.remove_prefix(colonPos + 1);
68+
}
69+
70+
if (shortenLength && id.length() > shortLen)
71+
{
72+
return std::basic_string<TChar>{id.substr(0, shortLen)};
73+
}
74+
75+
return std::basic_string<TChar>{id};
76+
}
77+
5178
struct PhysicalMacAddress
5279
{
5380
BYTE Address[MAX_ADAPTER_ADDRESS_LENGTH]{};

src/windows/wslc/arguments/ArgumentDefinitions.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -61,6 +61,7 @@ _(Interactive, "interactive", L"i", Kind::Flag, L
6161
_(Name, "name", NO_ALIAS, Kind::Value, L"Name of the container") \
6262
/*_(NoDNS, "no-dns", NO_ALIAS, Kind::Flag, L"No configuration of DNS in the container")*/ \
6363
_(NoPrune, "no-prune", NO_ALIAS, Kind::Flag, L"Do not delete untagged parents") \
64+
_(NoTrunc, "no-trunc", NO_ALIAS, Kind::Flag, L"Do not truncate output") \
6465
_(Output, "output", L"o", Kind::Value, L"Path for the saved image") \
6566
_(Path, "path", NO_ALIAS, Kind::Positional, L"Path to the build context directory") \
6667
/*_(Progress, "progress", NO_ALIAS, Kind::Value, L"Progress type (format: none|ansi) (default: ansi)")*/ \

src/windows/wslc/commands/ContainerListCommand.cpp

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -29,6 +29,7 @@ std::vector<Argument> ContainerListCommand::GetArguments() const
2929
return {
3030
Argument::Create(ArgType::All),
3131
Argument::Create(ArgType::Format),
32+
Argument::Create(ArgType::NoTrunc),
3233
Argument::Create(ArgType::Quiet),
3334
Argument::Create(ArgType::Session),
3435
};

src/windows/wslc/commands/ImageListCommand.cpp

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,7 +26,12 @@ namespace wsl::windows::wslc {
2626
// Image List Command
2727
std::vector<Argument> ImageListCommand::GetArguments() const
2828
{
29-
return {Argument::Create(ArgType::Format), Argument::Create(ArgType::Quiet), Argument::Create(ArgType::Session), Argument::Create(ArgType::Verbose)};
29+
return {
30+
Argument::Create(ArgType::Format),
31+
Argument::Create(ArgType::NoTrunc),
32+
Argument::Create(ArgType::Quiet),
33+
Argument::Create(ArgType::Session),
34+
Argument::Create(ArgType::Verbose)};
3035
}
3136

3237
std::wstring ImageListCommand::ShortDescription() const

0 commit comments

Comments
 (0)