Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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: 2 additions & 0 deletions src/windows/wslc/commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@ Module Name:
#include "ContainerCommand.h"
#include "ImageCommand.h"
#include "SessionCommand.h"
#include "VersionCommand.h"

using namespace wsl::windows::wslc::execution;

Expand All @@ -43,6 +44,7 @@ std::vector<std::unique_ptr<Command>> RootCommand::GetCommands() const
commands.push_back(std::make_unique<ContainerRunCommand>(FullName()));
commands.push_back(std::make_unique<ContainerStartCommand>(FullName()));
commands.push_back(std::make_unique<ContainerStopCommand>(FullName()));
commands.push_back(std::make_unique<VersionCommand>(FullName()));
return commands;
}

Expand Down
33 changes: 33 additions & 0 deletions src/windows/wslc/commands/VersionCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

VersionCommand.cpp

Abstract:

Implementation of the version command.

--*/
#include "VersionCommand.h"

using namespace wsl::windows::wslc::execution;

namespace wsl::windows::wslc {
std::wstring VersionCommand::ShortDescription() const
{
return {L"Show version information."};
}

std::wstring VersionCommand::LongDescription() const
{
return {L"Show version information for this tool."};
}

void VersionCommand::ExecuteInternal(CLIExecutionContext& context) const
{
wsl::windows::common::wslutil::PrintMessage(std::format(L"{} v{}", s_ExecutableName, WSL_PACKAGE_VERSION));
}
} // namespace wsl::windows::wslc
30 changes: 30 additions & 0 deletions src/windows/wslc/commands/VersionCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
/*++
Copyright (c) Microsoft. All rights reserved.
Module Name:
VersionCommand.h
Abstract:
Declaration of the VersionCommand.
--*/
#pragma once
#include "Command.h"

namespace wsl::windows::wslc {
struct VersionCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"version";
VersionCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

protected:
void ExecuteInternal(CLIExecutionContext& context) const override;
};
} // namespace wsl::windows::wslc
5 changes: 5 additions & 0 deletions test/windows/wslc/CommandLineTestCases.h
Original file line number Diff line number Diff line change
Expand Up @@ -111,6 +111,11 @@ COMMAND_LINE_TEST_CASE(L"image list -q", L"list", true)
COMMAND_LINE_TEST_CASE(L"image pull ubuntu", L"pull", true)
COMMAND_LINE_TEST_CASE(L"pull ubuntu", L"pull", true)

// Version command tests
COMMAND_LINE_TEST_CASE(L"version", L"version", true)
COMMAND_LINE_TEST_CASE(L"version --help", L"version", true)
COMMAND_LINE_TEST_CASE(L"version extraarg", L"version", false)

// Error cases
COMMAND_LINE_TEST_CASE(L"invalid command", L"", false)
COMMAND_LINE_TEST_CASE(L"CONTAINER list", L"list", false) // We are intentionally case-sensitive
Expand Down
41 changes: 41 additions & 0 deletions test/windows/wslc/WSLCCLICommandUnitTests.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ Module Name:
#include "RootCommand.h"
#include "ContainerCommand.h"
#include "SessionCommand.h"
#include "VersionCommand.h"

using namespace wsl::windows::wslc;
using namespace WSLCTestHelpers;
Expand Down Expand Up @@ -95,6 +96,46 @@ class WSLCCLICommandUnitTests
VERIFY_IS_NOT_NULL(subcmd.get());
}
}

// Test: Verify VersionCommand has the correct name
TEST_METHOD(VersionCommand_HasCorrectName)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(std::wstring_view(L"version"), cmd.Name());
}

// Test: Verify VersionCommand has no subcommands
TEST_METHOD(VersionCommand_HasNoSubcommands)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(0u, cmd.GetCommands().size());
}

// Test: Verify VersionCommand has no arguments (only the auto-added --help)
TEST_METHOD(VersionCommand_HasNoArguments)
{
auto cmd = VersionCommand(L"wslc");
VERIFY_ARE_EQUAL(0u, cmd.GetArguments().size());
}

// Test: Verify RootCommand contains VersionCommand as a subcommand
TEST_METHOD(RootCommand_ContainsVersionCommand)
{
auto root = RootCommand();
auto subcommands = root.GetCommands();

bool found = false;
for (const auto& subcmd : subcommands)
{
if (subcmd->Name() == VersionCommand::CommandName)
{
found = true;
break;
}
}

VERIFY_IS_TRUE(found, L"RootCommand should contain VersionCommand");
}
};

} // namespace WSLCCLICommandUnitTests
Loading