-
Notifications
You must be signed in to change notification settings - Fork 1.7k
Add Export/Import commands #699
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
Merged
Merged
Changes from all commits
Commits
Show all changes
35 commits
Select commit
Hold shift + click to select a range
dac55b5
Prototype of import/export
4d6c28a
Preserve unavailable packages on export; add option for exact versions
60109c5
typo
01c6b86
Lowercase command names
c89e8a0
Remove query arguments for export (except source)
6e0830f
Use Workflow::VerifyFile for import
d015f37
Move argument definitions to be in command definitions
9842b1f
Find sources by identifier instead of argument
2f46348
Style changes from review & better logging/reporting
c6408d7
Add tests for workflow & detect installed packages
8122ea8
Add unit tests for JSON read/write
8b07d23
Spell checking
c82d9cb
Disable schema validation
3c45df8
Add E2E tests
86101a8
Track installed version in test exe installer
508d094
Uninstall test exe before tests
b176066
Spell checking
1a30962
Fix test failure
576c051
Move and rename packages schema file
20aba26
Merge branch 'master' into ImportExport
5bcd4a2
Spell checking
33ba202
Fix error codes in tests after merge
660387d
Apply suggestions from code review
lechacon 20984c6
Remove exact versions import argument
7eb3359
Match sources with identifier and type
4c93054
Add execution stages
08b1604
Add --force argument to skip missing packages
dc8bcad
Rename ParseJson -> TryParseJson
f7a9c43
Use workflow task for building Sources vector
4b59e1a
Fix tests
8b45f6d
Change composite search behavior from flag to enum
58f6fe4
Address comments from review
1357453
Update behavior around versions
a09ad02
Fix tests
abd0e4c
Don't check that installed version is available unless needed
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
|
|
@@ -245,6 +245,9 @@ usersettingstest | |
| USHORT | ||
| Utils | ||
| UWP | ||
| validator | ||
| valijson | ||
| valueiterator | ||
| vamus | ||
| VERSI | ||
| VERSIE | ||
|
|
||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,97 @@ | ||
| { | ||
| "$id": "https://aka.ms/winget-packages.schema.json", | ||
| "$schema": "https://json-schema.org/draft/2019-09/schema#", | ||
|
|
||
| "title": "winget Packages List Schema", | ||
| "description": "Describes a list of packages for batch installs", | ||
|
|
||
| "type": "object", | ||
| "required": [ "WinGetVersion", "Sources" ], | ||
| "additionalProperties": true, | ||
|
|
||
| "properties": { | ||
| "WinGetVersion": { | ||
|
florelis marked this conversation as resolved.
|
||
| "description": "Version of winget that generated this file", | ||
| "type": "string", | ||
| "pattern": "^[0-9]+\\.[0-9]\\.[0-9]$" | ||
| }, | ||
|
|
||
| "CreationDate": { | ||
| "description": "Date when this list was generated", | ||
| "type": "string", | ||
| "format": "date-time" | ||
| }, | ||
|
|
||
| "Sources": { | ||
| "description": "Sources from which each package comes from", | ||
| "type": "array", | ||
|
|
||
| "items": { | ||
| "description": "A source and the list of packages to install from it", | ||
| "type": "object", | ||
| "required": [ "SourceDetails", "Packages" ], | ||
| "additionalProperties": true, | ||
|
|
||
| "properties": { | ||
| "SourceDetails": { | ||
| "description": "Details about this source", | ||
| "type": "object", | ||
| "required": [ "Name", "Identifier", "Argument", "Type" ], | ||
| "additionalProperties": true, | ||
|
|
||
| "properties": { | ||
| "Name": { | ||
| "description": "Name of the source", | ||
| "type": "string" | ||
| }, | ||
|
|
||
| "Identifier": { | ||
| "description": "Identifier for the source", | ||
| "type": "string" | ||
| }, | ||
|
|
||
| "Argument": { | ||
| "description": "Argument used to install the source", | ||
| "type": "string" | ||
| }, | ||
|
|
||
| "Type": { | ||
| "description": "Type of the source", | ||
| "type": "string" | ||
| } | ||
| } | ||
| }, | ||
|
|
||
| "Packages": { | ||
| "description": "Packages installed from this source", | ||
| "type": "array", | ||
| "required": [ "Id" ], | ||
| "minItems": 1, | ||
|
|
||
| "items": { | ||
| "description": "A package to be installed from this source", | ||
| "type": "object", | ||
| "additionalProperties": true, | ||
| "properties": { | ||
| "Id": { | ||
| "description": "Package ID", | ||
| "type": "string" | ||
| }, | ||
|
|
||
| "Version": { | ||
| "description": "Package version", | ||
| "type": "string" | ||
| }, | ||
|
|
||
| "Channel": { | ||
| "description": "Package channel", | ||
| "type": "string" | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,66 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| #include "pch.h" | ||
| #include "ExportCommand.h" | ||
| #include "Workflows/CompletionFlow.h" | ||
| #include "Workflows/ImportExportFlow.h" | ||
| #include "Workflows/WorkflowBase.h" | ||
| #include "Resources.h" | ||
|
|
||
| namespace AppInstaller::CLI | ||
| { | ||
| using namespace std::string_view_literals; | ||
|
|
||
| std::vector<Argument> ExportCommand::GetArguments() const | ||
| { | ||
| return { | ||
| Argument{ "output", 'o', Execution::Args::Type::OutputFile, Resource::String::OutputFileArgumentDescription, ArgumentType::Positional, true }, | ||
| Argument{ "source", 's', Execution::Args::Type::Source, Resource::String::ExportSourceArgumentDescription, ArgumentType::Standard }, | ||
| Argument{ "include-versions", Argument::NoAlias, Execution::Args::Type::IncludeVersions, Resource::String::ExportIncludeVersionsArgumentDescription, ArgumentType::Flag }, | ||
| }; | ||
| } | ||
|
|
||
| Resource::LocString ExportCommand::ShortDescription() const | ||
| { | ||
| return { Resource::String::ExportCommandShortDescription }; | ||
| } | ||
|
|
||
| Resource::LocString ExportCommand::LongDescription() const | ||
| { | ||
| return { Resource::String::ExportCommandLongDescription }; | ||
| } | ||
|
|
||
| void ExportCommand::Complete(Execution::Context& context, Execution::Args::Type valueType) const | ||
| { | ||
| if (valueType == Execution::Args::Type::OutputFile) | ||
| { | ||
| // Intentionally output nothing to allow pass through to filesystem. | ||
| return; | ||
| } | ||
|
|
||
| if (valueType == Execution::Args::Type::Source) | ||
| { | ||
| context << Workflow::CompleteSourceName; | ||
| return; | ||
| } | ||
| } | ||
|
|
||
| std::string ExportCommand::HelpLink() const | ||
| { | ||
| // TODO: point to correct location | ||
| return "https://aka.ms/winget-command-export"; | ||
| } | ||
|
|
||
| void ExportCommand::ExecuteInternal(Execution::Context& context) const | ||
| { | ||
| context << | ||
|
florelis marked this conversation as resolved.
|
||
| Workflow::ReportExecutionStage(Workflow::ExecutionStage::Discovery) << | ||
| Workflow::OpenSource << | ||
| Workflow::OpenCompositeSource(Repository::PredefinedSource::Installed) << | ||
| Workflow::SearchSourceForMany << | ||
| Workflow::EnsureMatchesFromSearchResult(true) << | ||
| Workflow::SelectVersionsToExport << | ||
| Workflow::ReportExecutionStage(Workflow::ExecutionStage::Execution) << | ||
| Workflow::WriteImportFile; | ||
| } | ||
| } | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1,25 @@ | ||
| // Copyright (c) Microsoft Corporation. | ||
| // Licensed under the MIT License. | ||
| #pragma once | ||
| #include "Command.h" | ||
|
|
||
| namespace AppInstaller::CLI | ||
| { | ||
| // Command to get the set of installed packages on the system. | ||
| struct ExportCommand final : public Command | ||
| { | ||
| ExportCommand(std::string_view parent) : Command("export", parent, Settings::ExperimentalFeature::Feature::ExperimentalImportExport) {} | ||
|
|
||
| std::vector<Argument> GetArguments() const override; | ||
|
|
||
| Resource::LocString ShortDescription() const override; | ||
| Resource::LocString LongDescription() const override; | ||
|
|
||
| void Complete(Execution::Context& context, Execution::Args::Type valueType) const override; | ||
|
|
||
| std::string HelpLink() const override; | ||
|
|
||
| protected: | ||
| void ExecuteInternal(Execution::Context& context) const override; | ||
| }; | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
#699 (comment)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This is not in the product code or tests directly, but in a standalone .exe used as a test installer. It was mixing narrow and wide chars and that was getting complicated, but it didn't seem worth it to add conversion between them there, so I moved it all to wide. It should be fine as it's independent of everything else.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The only thing I'd note is that by using it here instead of, e.g. just telling the bot to ignore the file entirely, the bot will never warn about the next violation.
Think of it like page-fault protection.
Obviously reviewers are responsible for the content, so in theory some reviewer should catch future incursions.
(Just feedback from the peanut gallery.)