diff --git a/Documentation/FindIt.md b/Documentation/FindIt.md new file mode 100644 index 0000000..be6e18e --- /dev/null +++ b/Documentation/FindIt.md @@ -0,0 +1,70 @@ +# Find It 🔍 + +### A Work In Progress 👷 + +For now, support `$ tryswiftdev -f -name ` only. 🙏 + +
+ + + +
+ +## Example + +### Building your project _Pokemon_ with Xcode + +``` +ld: framework not found sourcekitd +clang: error: linker command failed with exit code 1 (use -v to see invocation) +``` + +### 🤔 + +
+ +### Running your project _Pokemon_ with Xcode + +``` +dyld: Library not loaded: @rpath/sourcekitd.framework/Versions/A/sourcekitd + Referenced from: /usr/local/bin/pokemon + Reason: image not found +``` + +### 🙄 + +
+ +### Finding it with _tryswiftdev_ + +```bash +$ tryswiftdev -f -name sourcekitd.framework +``` + +``` +Searching... /Applications/Xcode.app/Contents +Searching... /Library/Developer +Searching... /Library/Frameworks + +Found it! + + - /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/lib/sourcekitd.framework + + - /Library/Developer/Toolchains/swift-2.2-SNAPSHOT-2016-03-01-a.xctoolchain/usr/lib/sourcekitd.framework + + - /Library/Developer/Toolchains/swift-DEVELOPMENT-SNAPSHOT-2016-04-25-a.xctoolchain/usr/lib/sourcekitd.framework + + +(Check your `Runpath Search Paths`, `Framework Search Paths`, etc.) +``` + +### 😇 + +
+ +## ToDo + +- [ ] Error Handling +- [ ] Tests + +etc. diff --git a/Documentation/Images/FindIt.png b/Documentation/Images/FindIt.png new file mode 100644 index 0000000..77318c1 Binary files /dev/null and b/Documentation/Images/FindIt.png differ diff --git a/Documentation/Images/tryswiftdev.png b/Documentation/Images/tryswiftdev.png index b413607..e8ee0c7 100644 Binary files a/Documentation/Images/tryswiftdev.png and b/Documentation/Images/tryswiftdev.png differ diff --git a/README.md b/README.md index be117e6..6eb9c92 100644 --- a/README.md +++ b/README.md @@ -43,9 +43,12 @@ $ tryswiftdev Do not overwrite an existing file. -r [--replace-readme] Replace strings in a README.md located in the current directory. +-f [--find] Search for specified file. ✨ -h [--help] Display available options. ``` +For more information about the `-f` option, please see [Find It](./Documentation/FindIt.md). +
## Example @@ -94,9 +97,19 @@ HomeDirectory
+### Finding It + +```bash +$ tryswiftdev -f -name sourcekitd.framework +``` + +For more information, please see [Find It](./Documentation/FindIt.md). + +
+ ## Availability -Recommend Swift 3.0-dev. +Swift 3.0-dev
diff --git a/Sources/Command.swift b/Sources/Command.swift index f7ccb52..00bb6bc 100644 --- a/Sources/Command.swift +++ b/Sources/Command.swift @@ -20,16 +20,19 @@ func executeCommand(argments args: [String]) -> [String]? { close(pipe[1]) - let N = 4096 - var buf = [Int8](repeating: 0, count: N + 1) + let bufferSize = 4096 + var buffer = [Int8](repeating: 0, count: bufferSize + 1) var n: Int var outputStrings = [String]() + + // FIXME: Return value is not correct value when executing `$ xcodebuild -showBuildSettings`. repeat { - n = read(pipe[0], &buf, N) - if let output = String(validatingUTF8: buf) { + n = read(pipe[0], &buffer, bufferSize) + if let output = String(validatingUTF8: buffer) { outputStrings.append(output) } + buffer = [Int8](repeating: 0, count: bufferSize) } while n > 0 close(pipe[0]) diff --git a/Sources/Error.swift b/Sources/Error.swift index 5ef2ffb..8d93daa 100644 --- a/Sources/Error.swift +++ b/Sources/Error.swift @@ -5,6 +5,7 @@ enum Error: ErrorProtocol { case InvalidValue + case UnsupportedOption } extension Error: CustomStringConvertible { @@ -12,6 +13,8 @@ extension Error: CustomStringConvertible { switch self { case .InvalidValue: return "Please input [option ...]." + case .UnsupportedOption: + return "Please input `tryswift -f -name `." } } } diff --git a/Sources/FindIt.swift b/Sources/FindIt.swift new file mode 100644 index 0000000..1aedcf8 --- /dev/null +++ b/Sources/FindIt.swift @@ -0,0 +1,29 @@ +let maybeHere = [ + "/Applications/Xcode.app/Contents", + "/Library/Developer", + "/Library/Frameworks", +] + +func findFile(targetOption option: String, targetName name: String) { + print("") + var existingFilePaths = [String]() + maybeHere.forEach { + print("Searching... \($0)") + guard let outputStrings = executeCommand(argments: ["find", $0, option, name]) else { return } + existingFilePaths.append(contentsOf: outputStrings) + } + displayResult(sources: parseToArray(source: existingFilePaths.reduce("", combine: { $0 + $1 }))) +} + +func displayResult(sources: [String]) { + print("") + guard !sources.isEmpty else { + print("Not found.") + return + } + print("Found it!") + print("") + sources.forEach { print(" - \($0)\n") } + print("") + print("(Check your `Runpath Search Paths`, `Framework Search Paths`, etc.)") +} diff --git a/Sources/Option.swift b/Sources/Option.swift index c7e2bdc..6fb47f9 100644 --- a/Sources/Option.swift +++ b/Sources/Option.swift @@ -1,6 +1,7 @@ enum Options: String, CustomStringConvertible { case DuplicateReadme case ReplaceStringsInReadme + case FindIt case Usage init?(argment: String) { @@ -9,6 +10,8 @@ enum Options: String, CustomStringConvertible { self = .DuplicateReadme case "-r", "--replace-readme": self = .ReplaceStringsInReadme + case "-f", "--find": + self = .FindIt case "-h", "--help": self = .Usage default: @@ -24,6 +27,8 @@ enum Options: String, CustomStringConvertible { case .ReplaceStringsInReadme: return "Replace strings in a README.md" + "\n located in the current directory." + case .FindIt: + return "Search for specified file." case .Usage: return "Display available options." } diff --git a/Sources/Parse.swift b/Sources/Parse.swift new file mode 100644 index 0000000..7aeea40 --- /dev/null +++ b/Sources/Parse.swift @@ -0,0 +1,3 @@ +func parseToArray(source: String) -> [String] { + return source.characters.split(separator: "\n").map { String($0) } +} diff --git a/Sources/Usage.swift b/Sources/Usage.swift index 1678638..ad2f1af 100644 --- a/Sources/Usage.swift +++ b/Sources/Usage.swift @@ -8,6 +8,7 @@ func usage() { print("OPTIONS:") print(" -d [--duplicate-readme] \(Options.DuplicateReadme.description)") print(" -r [--replace-readme] \(Options.ReplaceStringsInReadme.description)") + print(" -f [--find] \(Options.FindIt.description)") print(" -h [--help] \(Options.Usage.description)") print("") print("USAGE:") @@ -16,6 +17,7 @@ func usage() { print("EXAMPLE:") print(" $ tryswiftdev -d ./Pokemon ./DragonBall") print(" $ tryswiftdev -r Pokemon DragonBall") + print(" $ tryswiftdev -f -name sourcekitd.framework") print("") print("_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/_/") print("") diff --git a/Sources/main.swift b/Sources/main.swift index 415c1fc..3604c53 100644 --- a/Sources/main.swift +++ b/Sources/main.swift @@ -22,10 +22,17 @@ do { duplicateExistingReadme(existingReadmeDirctoryPath: value1, newReadmeDirectoryPath: value2) case .ReplaceStringsInReadme: replaceStringsInReadme(source: value1, target: value2) + case .FindIt: + guard value1 == "-name" else { + // TODO: For now, support `-name` only. + throw Error.UnsupportedOption + } + findFile(targetOption: "-name", targetName: value2) case .Usage: usage() } } catch let error as Error { + print("") print(error.description) } catch { // TODO: Error Handling