-
Notifications
You must be signed in to change notification settings - Fork 47
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Add attachments sub-command & allow attachment UTI filtering (#25)
Change Description: These changes add a new "attachments" sub-command. This command will by default export all attachments in the xcresult regardless of uniform type identifier (what screenshots used to be doing). Users can provide a list of UTIs to filter with (ex. "--uti public.plain-text") to only export attachments which conform to the given UTI. This would be useful for folks who want to get all the debug descriptions, for example. The screenshots command has bee modified so that it'll only export image attachments & not other files such as text debug descriptions from test failures. It does this by taking advantage of the UTI filtering & using "public.image" UTI. Test Plan/Testing Performed: Tested that with these changes, I can now export attachments that conform to plain text or image UTIs and avoid exporting everything.
- Loading branch information
1 parent
3e2d6c5
commit d09a5e9
Showing
7 changed files
with
140 additions
and
24 deletions.
There are no files selected for viewing
This file contains 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 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 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,86 @@ | ||
// | ||
// AttachmentsCommand.swift | ||
// xcparse | ||
// | ||
// Created by Alex Botkin on 10/16/19. | ||
// Copyright © 2019 ChargePoint, Inc. All rights reserved. | ||
// | ||
|
||
import Basic | ||
import Foundation | ||
import SPMUtility | ||
|
||
struct AttachmentsCommand: Command { | ||
let command = "attachments" | ||
let overview = "Extracts attachments from xcresult and saves it in output folder." | ||
let usage = "[OPTIONS] xcresult [outputDirectory]" | ||
|
||
var path: PositionalArgument<PathArgument> | ||
var outputPath: PositionalArgument<PathArgument> | ||
var verbose: OptionArgument<Bool> | ||
|
||
var divideByModel: OptionArgument<Bool> | ||
var divideByOS: OptionArgument<Bool> | ||
var divideByTestPlanRun: OptionArgument<Bool> | ||
|
||
var utiWhitelist: OptionArgument<[String]> | ||
|
||
init(parser: ArgumentParser) { | ||
let subparser = parser.add(subparser: command, usage: usage, overview: overview) | ||
path = subparser.add(positional: "xcresult", kind: PathArgument.self, | ||
optional: false, usage: "Path to the xcresult file", completion: .filename) | ||
outputPath = subparser.add(positional: "outputDirectory", kind: PathArgument.self, | ||
optional: true, usage: "Folder to export results to", completion: .filename) | ||
verbose = subparser.add(option: "--verbose", shortName: "-v", kind: Bool.self, usage: "Enable verbose logging") | ||
|
||
divideByModel = subparser.add(option: "--model", shortName: nil, kind: Bool.self, usage: "Divide attachments by model") | ||
divideByOS = subparser.add(option: "--os", shortName: nil, kind: Bool.self, usage: "Divide attachments by OS") | ||
divideByTestPlanRun = subparser.add(option: "--test-run", shortName: nil, kind: Bool.self, usage: "Divide attachments by test plan configuration") | ||
|
||
utiWhitelist = subparser.add(option: "--uti", shortName: nil, kind: [String].self, strategy: .upToNextOption, | ||
usage: "Takes list of uniform type identifiers (UTI) and export only attachments that conform to at least one") | ||
} | ||
|
||
func run(with arguments: ArgumentParser.Result) throws { | ||
guard let xcresultPathArgument = arguments.get(path) else { | ||
print("Missing xcresult path") | ||
return | ||
} | ||
let xcresultPath = xcresultPathArgument.path | ||
|
||
var outputPath: AbsolutePath | ||
if let outputPathArgument = arguments.get(self.outputPath) { | ||
outputPath = outputPathArgument.path | ||
} else if let workingDirectory = localFileSystem.currentWorkingDirectory { | ||
outputPath = workingDirectory | ||
} else { | ||
print("Missing output path") | ||
return | ||
} | ||
|
||
let verbose = arguments.get(self.verbose) ?? false | ||
|
||
let xcpParser = XCPParser() | ||
xcpParser.console.verbose = verbose | ||
|
||
var options = AttachmentExportOptions(addTestScreenshotsDirectory: false, | ||
divideByTargetModel: arguments.get(self.divideByModel) ?? false, | ||
divideByTargetOS: arguments.get(self.divideByOS) ?? false, | ||
divideByTestRun: arguments.get(self.divideByTestPlanRun) ?? false) | ||
if let allowedUTIsToExport = arguments.get(self.utiWhitelist) { | ||
options.attachmentFilter = { | ||
let attachmentUTI = $0.uniformTypeIdentifier as CFString | ||
for allowedUTI in allowedUTIsToExport { | ||
if UTTypeConformsTo(attachmentUTI, allowedUTI as CFString) { | ||
return true | ||
} | ||
} | ||
return false | ||
} | ||
} | ||
|
||
try xcpParser.extractAttachments(xcresultPath: xcresultPath.pathString, | ||
destination: outputPath.pathString, | ||
options: options) | ||
} | ||
} |
This file contains 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 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 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 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