Skip to content
Draft
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
4 changes: 4 additions & 0 deletions localization/strings/en-US/Resources.resw
Original file line number Diff line number Diff line change
Expand Up @@ -3107,6 +3107,10 @@ On first run, creates the file with all settings commented out at their defaults
<value>Specify volume driver name, e.g. 'guest' or 'vhd' (default: guest)</value>
<comment>{Locked="guest"}{Locked="vhd"}Command line arguments, file names and string inserts should not be translated</comment>
</data>
<data name="WSLCCLI_DriverEmptyError" xml:space="preserve">
<value>Invalid {} value: driver name cannot be empty or whitespace</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>
Expand Down
11 changes: 11 additions & 0 deletions src/windows/wslc/arguments/ArgumentValidation.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,17 @@ void Argument::Validate(const ArgMap& execArgs) const
break;
}

case ArgType::Driver:
{
const auto& value = execArgs.Get<ArgType::Driver>();
if (value.empty() ||

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

I think a standard validator for checking an argument is not empty or whitespace would be useful since we have now used it in multiple places. We have this for validating integers and such, so it makes sense to me that we'd have this as a standard validator that would likely be applicable for many value arguments in the future. A simple boolean result would allow us to still have separate exception messages for each argument but share the same empty/whitespace check.

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

I guess, I wonder if for those cases we should just fall back to using default (from runtime side). Again, I suspect this is a nit, but would be usefult for something like:

wslc network create --driver "$WSLC_DRIVER"

where if $WSLC_DRIVER is defined, then it is used, and if not the runtime would fallback to the default one. Again, not sure if those are valid use cases, but thinking out loud ✨

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

With the environment variable support pr we could add argument-specific environment variables such as this if we want to do that so the user can set their own default driver and not specify it, but I would think that's some nice convenience polish for GA and not something urgent.

With regards to falling bak on default, if the user enters emptystring or whitepsace for an argument value that is a big red flag to me that they made an argument CLI error, not that they intend to use a default value. I think that should be treated as an error and not a signal from the user to use the default. If they wanted to use the default they wouldn't specify anything at all.

std::all_of(value.begin(), value.end(), [](wchar_t c) { return std::iswspace(static_cast<wint_t>(c)); }))
{
throw ArgumentException(Localization::WSLCCLI_DriverEmptyError(m_name));
}
break;
}

case ArgType::Network:
{
for (const auto& value : execArgs.GetAll<ArgType::Network>())
Expand Down
2 changes: 1 addition & 1 deletion src/windows/wslc/services/ContainerService.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -72,7 +72,7 @@ static wsl::windows::common::RunningWSLCContainer CreateInternal(
THROW_HR_WITH_USER_ERROR_IF(
E_INVALIDARG,
Localization::MessageWslcAliasRequiresUserDefinedNetwork(),
primary == "bridge" || primary == "host" || primary == "none" || primary.starts_with("container:"));
primary.empty() || primary == "bridge" || primary == "host" || primary == "none" || primary.starts_with("container:"));

for (const auto& alias : options.NetworkAliases)
{
Expand Down