-
Notifications
You must be signed in to change notification settings - Fork 1.8k
Add wslc container cp command for tar archive upload #40835
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
base: master
Are you sure you want to change the base?
Changes from all commits
e2eddc9
2c30479
960603f
b148cca
ff5aeb4
dc3fa26
dabe0e0
e64028c
cdea6af
dbe37e7
27286c3
fc3913e
9ce3d58
ebb5f66
ce3ef82
aadb355
d5210bb
b5193a6
b9c2240
565fca3
e298698
4d8283e
0b2b16f
739ec44
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -17,6 +17,24 @@ Module Name: | |
| using namespace wsl::shared; | ||
|
|
||
| namespace wsl::windows::wslc { | ||
|
|
||
| // Parses a boolean string value (true/false/1/0, case-insensitive). | ||
| // Returns the parsed value, or std::nullopt if the string is not a valid boolean. | ||
| static std::optional<bool> ParseBoolValue(std::wstring_view value) | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Not necessarily a blocker, but in the future I think we should separate parser changes from new commands being introduced. This will make changes smaller and easier to review |
||
| { | ||
| if (string::IsEqual(value, L"true") || value == L"1") | ||
|
Collaborator
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I recommend using |
||
| { | ||
| return true; | ||
| } | ||
|
|
||
| if (string::IsEqual(value, L"false") || value == L"0") | ||
| { | ||
| return false; | ||
| } | ||
|
|
||
| return std::nullopt; | ||
| } | ||
|
|
||
| ParseArgumentsStateMachine::ParseArgumentsStateMachine( | ||
| Invocation& inv, ArgMap& execArgs, std::vector<Argument> arguments, bool optionsOnly, bool stopOnUnknown, const std::vector<Argument>& overridableDefaults) : | ||
| m_invocation(inv), | ||
|
|
@@ -124,8 +142,6 @@ void ParseArgumentsStateMachine::AddFlag(ArgType type) | |
| if (!ConsumeOverrideIfPresent(type) && m_executionArgs.Contains(type)) | ||
| { | ||
| // Repeating the same flag on the CLI is a no-op, matching docker. | ||
| // TODO: revisit when --flag=value (explicit bool) lands so a mismatch | ||
| // between env-preload and CLI-explicit can warn or error. | ||
| return; | ||
| } | ||
|
|
||
|
|
@@ -343,9 +359,24 @@ ParseArgumentsStateMachine::State ParseArgumentsStateMachine::ProcessAliasArgume | |
| return {}; | ||
| } | ||
|
|
||
| // Boolean flag - add it and process any adjoined flags. Once we have added a | ||
| // flag to m_executionArgs for this token, stopOnUnknown no longer applies for | ||
| // mid-chain unknowns; the token has already been claimed. | ||
| // Boolean flag - check for adjoined boolean value (e.g., -a=true or -a=false). | ||
| if (currentPos < currArg.length() && currArg[currentPos] == WSLC_CLI_ARG_SPLIT_CHAR) | ||
| { | ||
| auto boolVal = ParseBoolValue(currArg.substr(currentPos + 1)); | ||
| if (!boolVal.has_value()) | ||
| { | ||
| return ArgumentException(Localization::WSLCCLI_FlagInvalidBooleanError(currArg)); | ||
| } | ||
|
|
||
| if (boolVal.value()) | ||
| { | ||
| AddFlag(firstArg->Type()); | ||
| } | ||
|
ptrivedi marked this conversation as resolved.
|
||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| // No adjoined value — add the flag as true. | ||
| AddFlag(firstArg->Type()); | ||
|
|
||
| // Process remaining adjoined flags | ||
|
|
@@ -381,6 +412,23 @@ ParseArgumentsStateMachine::State ParseArgumentsStateMachine::ProcessAliasArgume | |
| return {}; | ||
| } | ||
|
|
||
| // Boolean flag in chain — check for adjoined boolean value. | ||
| if (nextPos < currArg.length() && currArg[nextPos] == WSLC_CLI_ARG_SPLIT_CHAR) | ||
| { | ||
| auto boolVal = ParseBoolValue(currArg.substr(nextPos + 1)); | ||
| if (!boolVal.has_value()) | ||
| { | ||
| return ArgumentException(Localization::WSLCCLI_FlagInvalidBooleanError(currArg)); | ||
| } | ||
|
|
||
| if (boolVal.value()) | ||
| { | ||
| AddFlag(nextArg->Type()); | ||
| } | ||
|
Comment on lines
+424
to
+427
|
||
|
|
||
| return {}; | ||
| } | ||
|
|
||
| AddFlag(nextArg->Type()); | ||
| currentPos = nextPos; | ||
| } | ||
|
|
@@ -430,10 +478,20 @@ ParseArgumentsStateMachine::State ParseArgumentsStateMachine::ProcessNamedArgume | |
| // Found a match, process by kind. | ||
| if (arg.Kind() == Kind::Flag) | ||
| { | ||
| // TODO: Consider supporting --flag and --flag=true or --flag=false for bool args. | ||
| if (hasAdjoinedValue) | ||
| { | ||
| return ArgumentException(Localization::WSLCCLI_FlagContainAdjoinedError(currArg)); | ||
| auto boolVal = ParseBoolValue(argValue); | ||
| if (!boolVal.has_value()) | ||
| { | ||
|
ptrivedi marked this conversation as resolved.
ptrivedi marked this conversation as resolved.
ptrivedi marked this conversation as resolved.
|
||
| return ArgumentException(Localization::WSLCCLI_FlagInvalidBooleanError(currArg)); | ||
| } | ||
|
|
||
| if (boolVal.value()) | ||
| { | ||
| AddFlag(arg.Type()); | ||
| } | ||
|
ptrivedi marked this conversation as resolved.
|
||
|
|
||
| return {}; | ||
|
ptrivedi marked this conversation as resolved.
|
||
| } | ||
|
ptrivedi marked this conversation as resolved.
|
||
|
|
||
| AddFlag(arg.Type()); | ||
|
|
||
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,40 @@ | ||
| // Copyright (C) Microsoft Corporation. All rights reserved. | ||
|
|
||
| #include "ContainerCommand.h" | ||
| #include "CLIExecutionContext.h" | ||
| #include "ContainerTasks.h" | ||
| #include "SessionTasks.h" | ||
| #include "Task.h" | ||
|
|
||
| using namespace wsl::windows::wslc::execution; | ||
| using namespace wsl::windows::wslc::task; | ||
| using namespace wsl::shared; | ||
|
|
||
| namespace wsl::windows::wslc { | ||
| // Container Cp Command | ||
| std::vector<Argument> ContainerCpCommand::GetArguments() const | ||
| { | ||
| return { | ||
| Argument::Create(ArgType::Archive), | ||
| Argument::Create(ArgType::Source, true, std::nullopt, Localization::WSLCCLI_CpSourceArgDescription()), | ||
| Argument::Create(ArgType::Target, true, std::nullopt, Localization::WSLCCLI_CpTargetArgDescription()), | ||
| }; | ||
| } | ||
|
|
||
| std::wstring ContainerCpCommand::ShortDescription() const | ||
| { | ||
| return Localization::WSLCCLI_ContainerCpDesc(); | ||
| } | ||
|
|
||
| std::wstring ContainerCpCommand::LongDescription() const | ||
| { | ||
| return Localization::WSLCCLI_ContainerCpLongDesc(); | ||
| } | ||
|
|
||
| void ContainerCpCommand::ExecuteInternal(CLIExecutionContext& context) const | ||
| { | ||
| context // | ||
| << CreateSession // | ||
| << ContainerCp; | ||
| } | ||
| } // namespace wsl::windows::wslc |
Uh oh!
There was an error while loading. Please reload this page.