diff --git a/Sources/CommandLine/Commands/CleanCommand.swift b/Sources/CommandLine/Commands/CleanCommand.swift index 552b151..b1d08b0 100644 --- a/Sources/CommandLine/Commands/CleanCommand.swift +++ b/Sources/CommandLine/Commands/CleanCommand.swift @@ -1,24 +1,53 @@ import ArgumentParser import Foundation import Utils +import BinaryDependencyManager struct CleanCommand: ParsableCommand { static var configuration = CommandConfiguration(commandName: "clean") - // Path to cache directory - @Option(name: .shortAndLong, help: "Path to cache directory") - var cacheDirectoryPath: String + /// Path to the output directory. + /// + /// Example: + /// ``` + /// $ binary-dependencies-manager clean --output ./output + /// $ binary-dependencies-manager clean -o ./output + /// ``` + @Option(name: [.customLong("output"), .short], help: "Path to the output directory, where downloaded dependencies will be placed") + var outputDirectoryPath: String? - // Path to output directory - @Option(name: .shortAndLong, help: "Path to output directory, where downloaded dependencies will be placed") - var outputDirectoryPath: String + /// Path to the cache directory. + /// + /// Example: + /// ``` + /// $ binary-dependencies-manager clean --cache ./cache + /// ``` + @Option(name: [.customLong("cache")], help: "Path to the cache directory") + var cacheDirectoryPath: String? + + /// Validates a given configuration file. + mutating func validate() throws { + let configurationReader: BinaryDependenciesConfigurationReader = .init() + + outputDirectoryPath = configurationReader + .resolveOutputDirectoryURL(outputDirectoryPath) + .filePath + cacheDirectoryPath = configurationReader + .resolveCacheDirectoryURL(cacheDirectoryPath) + .filePath + } func run() throws { - Logger.log("#Cleanup# Removing \(outputDirectoryPath)") - try? FileManager.default.removeItem(atPath: outputDirectoryPath) - Logger.log("#Cleanup# Removing \(cacheDirectoryPath)") - try? FileManager.default.removeItem(atPath: cacheDirectoryPath) + if let outputDirectoryPath { + Logger.log("#Cleanup# Removing \(outputDirectoryPath)") + try? FileManager.default.removeItem(at: outputDirectoryPath.asFileURL) + } + + if let cacheDirectoryPath { + Logger.log("#Cleanup# Removing \(cacheDirectoryPath)") + try? FileManager.default.removeItem(at: cacheDirectoryPath.asFileURL) + } } }