-
Notifications
You must be signed in to change notification settings - Fork 0
chore: refactor resolve command #15
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
6 commits
Select commit
Hold shift + click to select a range
91174c7
chore: refactor resolve command
nekrich baabb26
chore: update resolve command
nekrich f626636
chore: add precondition
nekrich a022869
chore: add easter egg
nekrich fe018d4
chore: store dependenciesResolver
nekrich 3d5d165
chore: fix unwrapping
nekrich 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 |
|---|---|---|
| @@ -1,28 +1,87 @@ | ||
| import ArgumentParser | ||
| import BinaryDependencyManager | ||
| import Foundation | ||
| import Yams | ||
| import Utils | ||
|
|
||
| struct ResolveCommand: ParsableCommand { | ||
| static var configuration = CommandConfiguration( | ||
| commandName: "resolve", | ||
| version: BinaryDependenciesManager.configuration.version | ||
| ) | ||
|
|
||
| static var configuration = CommandConfiguration(commandName: "resolve") | ||
| /// Path to the configuration file. | ||
| /// | ||
| /// Example: | ||
| /// ``` | ||
| /// $ binary-dependencies-manager resolve --config ./.binary-dependencies.yaml | ||
| /// $ binary-dependencies-manager resolve -c ./.binary-dependencies.yaml | ||
| /// ``` | ||
| @Option(name: [.customLong("config", withSingleDash: true), .short], help: "Path to the configuration file") | ||
| var configurationFilePath: String? | ||
|
|
||
| // Path to dependencies json | ||
| @Option(name: .shortAndLong, help: "Path to dependencies json") | ||
| var dependenciesJSONPath: String | ||
| /// Path to the output directory. | ||
| /// | ||
| /// Example: | ||
| /// ``` | ||
| /// $ binary-dependencies-manager resolve --output ./output | ||
| /// $ binary-dependencies-manager resolve -o ./output | ||
| /// ``` | ||
| @Option(name: [.customLong("output"), .short], help: "Path to the output directory, where downloaded dependencies will be placed") | ||
| var outputDirectoryPath: String? | ||
|
|
||
| // Path to cache directory | ||
| @Option(name: .shortAndLong, help: "Path to cache directory") | ||
| var cacheDirectoryPath: String | ||
| /// Path to the cache directory. | ||
| /// | ||
| /// Example: | ||
| /// ``` | ||
| /// $ binary-dependencies-manager resolve --cache ./cache | ||
| /// ``` | ||
| @Option(name: [.customLong("cache")], help: "Path to the cache directory") | ||
| var cacheDirectoryPath: String? | ||
|
|
||
| // Path to output directory | ||
| @Option(name: .shortAndLong, help: "Path to output directory, where downloaded dependencies will be placed") | ||
| var outputDirectoryPath: String | ||
| /// Dependencies to resolve. | ||
| var configuration: BinaryDependenciesConfiguration? | ||
|
|
||
| /// Validates a given configuration file. | ||
| mutating func validate() throws { | ||
| let configurationReader: BinaryDependenciesConfigurationReader = .init() | ||
|
|
||
| let configuration = try configurationReader | ||
| .readConfiguration(at: configurationFilePath, currentToolVersion: BinaryDependenciesManager.version) | ||
|
|
||
| self.configuration = configuration | ||
|
|
||
| // Paths from CLI arguments take precedence over those from the configuration file. | ||
| outputDirectoryPath = configurationReader | ||
| .resolveOutputDirectoryURL(outputDirectoryPath ?? configuration.outputDirectory) | ||
| .path | ||
| cacheDirectoryPath = configurationReader | ||
| .resolveCacheDirectoryURL(cacheDirectoryPath ?? configuration.cacheDirectory) | ||
| .path | ||
|
|
||
| } | ||
|
|
||
| func run() throws { | ||
| let resolver = DependenciesResolverRunner( | ||
| dependenciesJSONPath: dependenciesJSONPath, | ||
| guard let configuration else { | ||
| // Should never happen, because we validate the configuration in `validate()` method. | ||
| preconditionFailure("Configuration is not initialized") | ||
| } | ||
| guard let outputDirectoryPath else { | ||
| // Should never happen, because we validate the configuration in `validate()` method. | ||
| preconditionFailure("Output directory path is not initialized") | ||
| } | ||
| guard let cacheDirectoryPath else { | ||
| // Should never happen, because we validate the configuration in `validate()` method. | ||
| preconditionFailure("Cache directory path is not initialized") | ||
| } | ||
|
|
||
| let dependenciesResolver = DependenciesResolverRunner( | ||
| dependencies: configuration.dependencies, | ||
| outputDirectoryPath: outputDirectoryPath, | ||
| cacheDirectoryPath: cacheDirectoryPath, | ||
| outputDirectoryPath: outputDirectoryPath | ||
| ) | ||
| try resolver.run() | ||
|
|
||
| // Run the dependencies resolver. | ||
| try dependenciesResolver.run() | ||
| } | ||
| } |
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.
:sigh: