Skip to content
45 changes: 45 additions & 0 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -2537,4 +2537,49 @@ On first run, creates the file with all settings commented out at their defaults
<data name="WSLCCLI_ImageLoadNoInputError" xml:space="preserve">
<value>Requested load but no input provided.</value>
</data>
<data name="WSLCCLI_VolumeCommandDesc" xml:space="preserve">
<value>Manage volumes.</value>
</data>
<data name="WSLCCLI_VolumeCommandLongDesc" xml:space="preserve">
<value>Manage the lifecycle of WSL volumes, including creating, inspecting, listing, and deleting them.</value>
<comment>{Locked="WSL"}Product names should not be translated</comment>
</data>
<data name="WSLCCLI_VolumeCreateDesc" xml:space="preserve">
<value>Create a volume.</value>
</data>
<data name="WSLCCLI_VolumeCreateLongDesc" xml:space="preserve">
<value>Creates a named volume that can be attached to containers.</value>
</data>
<data name="WSLCCLI_VolumeRemoveDesc" xml:space="preserve">
<value>Remove one or more volumes.</value>
</data>
<data name="WSLCCLI_VolumeRemoveLongDesc" xml:space="preserve">
<value>Removes one or more volumes. A volume cannot be removed if it is in use by a container.</value>
</data>
<data name="WSLCCLI_VolumeInspectDesc" xml:space="preserve">
<value>Display detailed information on one or more volumes.</value>
</data>
<data name="WSLCCLI_VolumeInspectLongDesc" xml:space="preserve">
<value>Display detailed information on one or more volumes.</value>
</data>
<data name="WSLCCLI_VolumeListDesc" xml:space="preserve">
<value>List volumes.</value>
</data>
<data name="WSLCCLI_VolumeListLongDesc" xml:space="preserve">
<value>Lists all volumes in the session.</value>
</data>
<data name="WSLCCLI_VolumeNameArgDescription" xml:space="preserve">
<value>Volume name</value>
</data>
<data name="WSLCCLI_DriverArgDescription" xml:space="preserve">
<value>Specify volume driver name (default {})</value>
<comment>{FixedPlaceholder="{}"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name="WSLCCLI_OptionsArgDescription" xml:space="preserve">
<value>Set driver specific options</value>
</data>
<data name="WSLCCLI_VolumeListQuietArgDesc" xml:space="preserve">
<value>Outputs the volume names only</value>
</data>

</root>
3 changes: 3 additions & 0 deletions src/windows/wslc/arguments/ArgumentDefinitions.h
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,7 @@ _(Detach, "detach", L"d", Kind::Flag, L
/*_(DNSDomain, "dns-domain", NO_ALIAS, Kind::Value, Localization::WSLCCLI_DNSDomainArgDescription())*/ \
/*_(DNSOption, "dns-option", NO_ALIAS, Kind::Value, Localization::WSLCCLI_DNSOptionArgDescription())*/ \
/*_(DNSSearch, "dns-search", NO_ALIAS, Kind::Value, Localization::WSLCCLI_DNSSearchArgDescription())*/ \
_(Driver, "driver", L"d", Kind::Value, Localization::WSLCCLI_DriverArgDescription("vhd")) \
_(Entrypoint, "entrypoint", NO_ALIAS, Kind::Value, Localization::WSLCCLI_EntrypointArgDescription()) \
_(Env, "env", L"e", Kind::Value, Localization::WSLCCLI_EnvArgDescription()) \
_(EnvFile, "env-file", NO_ALIAS, Kind::Value, Localization::WSLCCLI_EnvFileArgDescription()) \
Expand All @@ -62,6 +63,7 @@ _(Name, "name", NO_ALIAS, Kind::Value, L
/*_(NoDNS, "no-dns", NO_ALIAS, Kind::Flag, Localization::WSLCCLI_NoDNSArgDescription())*/ \
_(NoPrune, "no-prune", NO_ALIAS, Kind::Flag, Localization::WSLCCLI_NoPruneArgDescription()) \
_(NoTrunc, "no-trunc", NO_ALIAS, Kind::Flag, Localization::WSLCCLI_NoTruncArgDescription()) \
_(Options, "opt", L"o", Kind::Value, Localization::WSLCCLI_OptionsArgDescription()) \
_(Output, "output", L"o", Kind::Value, Localization::WSLCCLI_OutputArgDescription()) \
_(Path, "path", NO_ALIAS, Kind::Positional, Localization::WSLCCLI_PathArgDescription()) \
/*_(Progress, "progress", NO_ALIAS, Kind::Value, Localization::WSLCCLI_ProgressArgDescription())*/ \
Expand All @@ -85,5 +87,6 @@ _(Verbose, "verbose", NO_ALIAS, Kind::Flag, L
_(Version, "version", L"v", Kind::Flag, Localization::WSLCCLI_VersionArgDescription()) \
/*_(Virtual, "virtualization", NO_ALIAS, Kind::Value, Localization::WSLCCLI_VirtualArgDescription())*/ \
_(Volume, "volume", L"v", Kind::Value, Localization::WSLCCLI_VolumeArgDescription()) \
_(VolumeName, "volume-name", NO_ALIAS, Kind::Positional, Localization::WSLCCLI_VolumeNameArgDescription()) \
_(WorkDir, "workdir", L"w", Kind::Value, Localization::WSLCCLI_WorkingDirArgDescription()) \
// clang-format on
2 changes: 2 additions & 0 deletions src/windows/wslc/commands/RootCommand.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ Module Name:
#include "SessionCommand.h"
#include "SettingsCommand.h"
#include "VersionCommand.h"
#include "VolumeCommand.h"

using namespace wsl::windows::wslc::execution;
using namespace wsl::shared;
Expand All @@ -31,6 +32,7 @@ std::vector<std::unique_ptr<Command>> RootCommand::GetCommands() const
commands.push_back(std::make_unique<ImageCommand>(FullName()));
commands.push_back(std::make_unique<SessionCommand>(FullName()));
commands.push_back(std::make_unique<SettingsCommand>(FullName()));
commands.push_back(std::make_unique<VolumeCommand>(FullName()));
commands.push_back(std::make_unique<ContainerAttachCommand>(FullName()));
commands.push_back(std::make_unique<ImageBuildCommand>(FullName()));
commands.push_back(std::make_unique<ContainerCreateCommand>(FullName()));
Expand Down
51 changes: 51 additions & 0 deletions src/windows/wslc/commands/VolumeCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,51 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

VolumeCommand.cpp

Abstract:

Implementation of command execution logic.

--*/
#include "CLIExecutionContext.h"
#include "VolumeCommand.h"

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

namespace wsl::windows::wslc {
// Volume Root Command
std::vector<std::unique_ptr<Command>> VolumeCommand::GetCommands() const
{
std::vector<std::unique_ptr<Command>> commands;
commands.push_back(std::make_unique<VolumeCreateCommand>(FullName()));
commands.push_back(std::make_unique<VolumeRemoveCommand>(FullName()));
commands.push_back(std::make_unique<VolumeInspectCommand>(FullName()));
commands.push_back(std::make_unique<VolumeListCommand>(FullName()));
return commands;
}

std::vector<Argument> VolumeCommand::GetArguments() const
{
return {};
}

std::wstring VolumeCommand::ShortDescription() const
{
return Localization::WSLCCLI_VolumeCommandDesc();
}

std::wstring VolumeCommand::LongDescription() const
{
return Localization::WSLCCLI_VolumeCommandLongDesc();
}

void VolumeCommand::ExecuteInternal(CLIExecutionContext& context) const
{
OutputHelp();
}
} // namespace wsl::windows::wslc
95 changes: 95 additions & 0 deletions src/windows/wslc/commands/VolumeCommand.h
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

VolumeCommand.h

Abstract:

Declaration of command classes and interfaces.

--*/
#pragma once
#include "Command.h"

namespace wsl::windows::wslc {
// Root Volume Command
struct VolumeCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"volume";
VolumeCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

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

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

// Create Command
struct VolumeCreateCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"create";
VolumeCreateCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

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

// Remove Command
struct VolumeRemoveCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"remove";
VolumeRemoveCommand(const std::wstring& parent) : Command(CommandName, {L"delete", L"rm"}, parent)
{
}
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

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

// Inspect Command
struct VolumeInspectCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"inspect";
VolumeInspectCommand(const std::wstring& parent) : Command(CommandName, parent)
{
}
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

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

// List Command
struct VolumeListCommand final : public Command
{
constexpr static std::wstring_view CommandName = L"list";
VolumeListCommand(const std::wstring& parent) : Command(CommandName, {L"ls"}, parent)
{
}
std::vector<Argument> GetArguments() const override;
std::wstring ShortDescription() const override;
std::wstring LongDescription() const override;

protected:
void ValidateArgumentsInternal(const ArgMap& execArgs) const override;
void ExecuteInternal(CLIExecutionContext& context) const override;
};
} // namespace wsl::windows::wslc
52 changes: 52 additions & 0 deletions src/windows/wslc/commands/VolumeCreateCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,52 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

VolumeCreateCommand.cpp

Abstract:

Implementation of command execution logic.

--*/

#include "VolumeCommand.h"
#include "CLIExecutionContext.h"
#include "SessionTasks.h"
#include "VolumeTasks.h"
#include "Task.h"

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

namespace wsl::windows::wslc {
// Volume Create Command
std::vector<Argument> VolumeCreateCommand::GetArguments() const
{
return {
Argument::Create(ArgType::VolumeName, true),
Argument::Create(ArgType::Driver),
Argument::Create(ArgType::Options, false, NO_LIMIT),
Argument::Create(ArgType::Session),
};
}

std::wstring VolumeCreateCommand::ShortDescription() const
{
return Localization::WSLCCLI_VolumeCreateDesc();
}

std::wstring VolumeCreateCommand::LongDescription() const
{
return Localization::WSLCCLI_VolumeCreateLongDesc();
}

void VolumeCreateCommand::ExecuteInternal(CLIExecutionContext& context) const
{
context << CreateSession //
<< CreateVolume;
}
} // namespace wsl::windows::wslc
50 changes: 50 additions & 0 deletions src/windows/wslc/commands/VolumeInspectCommand.cpp
Original file line number Diff line number Diff line change
@@ -0,0 +1,50 @@
/*++

Copyright (c) Microsoft. All rights reserved.

Module Name:

VolumeInspectCommand.cpp

Abstract:

Implementation of command execution logic.

--*/

#include "VolumeCommand.h"
#include "CLIExecutionContext.h"
#include "SessionTasks.h"
#include "VolumeTasks.h"
#include "Task.h"

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

namespace wsl::windows::wslc {
// Volume Inspect Command
std::vector<Argument> VolumeInspectCommand::GetArguments() const
{
return {
Argument::Create(ArgType::VolumeName, true, NO_LIMIT),
Argument::Create(ArgType::Session),
};
}

std::wstring VolumeInspectCommand::ShortDescription() const
{
return Localization::WSLCCLI_VolumeInspectDesc();
}

std::wstring VolumeInspectCommand::LongDescription() const
{
return Localization::WSLCCLI_VolumeInspectLongDesc();
}

void VolumeInspectCommand::ExecuteInternal(CLIExecutionContext& context) const
{
context << CreateSession //
<< InspectVolumes;
}
} // namespace wsl::windows::wslc
Loading