Skip to content
Merged
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
49 changes: 39 additions & 10 deletions Sources/CommandLine/Commands/CleanCommand.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}