Skip to content

Commit

Permalink
Refactoring
Browse files Browse the repository at this point in the history
  • Loading branch information
ccal2 committed Jul 30, 2023
1 parent 92cb843 commit 74a4767
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 11 deletions.
16 changes: 8 additions & 8 deletions Swift-Metrics-Collector/SMCCLI/SMCCLI/Commands.swift
Original file line number Diff line number Diff line change
Expand Up @@ -14,16 +14,16 @@ struct SwiftMetricsCollector: ParsableCommand {

// MARK: - Constants

static private let defaultOutputPath: String = "~/Downloads/"
static private let defaultOutputDirectoryName: String = "swift-metrics-collector-output"
static private let defaultReportFileName: String = "report"
static private let defaultInheritanceTreeFileName: String = "inheritance-tree"
static private let defaultInheritanceTreeWithMetricsFileName: String = "inheritance-tree-with-metrics"
static private let defaultOutputPath: String = "~/Downloads/"
static private let defaultOutputDirectoryName: String = "swift-metrics-collector-output"

// MARK: - Arguments, flags and options

@Argument(help: "Path of the file to be analyzed")
var filePath: String
@Argument(help: "Path of the file or directory to be analyzed")
var path: String

@Flag(help: "Report file format")
var reportFormat: ReportFormat = .json
Expand All @@ -40,13 +40,13 @@ struct SwiftMetricsCollector: ParsableCommand {
// MARK: - Methods

func validate() throws {
let expandedPath = NSString(string: filePath).expandingTildeInPath
let expandedPath = NSString(string: path).expandingTildeInPath
guard FileManager.default.fileExists(atPath: expandedPath) else {
throw ValidationError("<file-path> \(filePath) doesn't exist.")
throw ValidationError("<path> \(path) doesn't exist.")
}

guard FileManager.default.isReadableFile(atPath: expandedPath) else {
throw ValidationError("<file-path> \(filePath) is not readable.")
throw ValidationError("<path> \(path) is not readable.")
}

guard outputDirectoryPath.last == "/" else {
Expand All @@ -67,7 +67,7 @@ struct SwiftMetricsCollector: ParsableCommand {
let collector = MetricsCollector(outputPath: outputDirectory)

do {
try collector.analyze(path: filePath)
try collector.analyze(path: path)
} catch {
// TODO: handle error
print(error)
Expand Down
5 changes: 2 additions & 3 deletions Swift-Metrics-Collector/SMCKit/SMCKit/MetricsCollector.swift
Original file line number Diff line number Diff line change
Expand Up @@ -133,15 +133,14 @@ public class MetricsCollector {

private func processFile(at filePath: String) throws {
let expandedPath = NSString(string: filePath).expandingTildeInPath
let fileURL = URL(fileURLWithPath: expandedPath)
let fileContent = try String(contentsOfFile: expandedPath, encoding: .utf8)

let fileURL = URL(fileURLWithPath: expandedPath)
guard let fileName = fileURL.deletingPathExtension().pathComponents.last else {
throw NSError(domain: "", code: 0)
}

visitor.newFileContext(named: fileName)

let fileContent = try String(contentsOfFile: expandedPath, encoding: .utf8)
process(content: fileContent)
}

Expand Down

0 comments on commit 74a4767

Please sign in to comment.