Skip to content

Commit

Permalink
Change to use Argument instead of Option on `IndexCommand.Options…
Browse files Browse the repository at this point in the history
….compilerargs`

Fix #480
  • Loading branch information
norio-nomura committed Feb 2, 2018
1 parent b2610c6 commit 4d3c277
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 8 deletions.
4 changes: 3 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,9 @@

##### Bug Fixes

* None.
* Fix `index` command fails using filename with spaces in compiler arguments.
[Norio Nomura](https://github.com/norio-nomura)
[#480](https://github.com/jpsim/SourceKitten/issues/480)

## 0.19.1

Expand Down
16 changes: 9 additions & 7 deletions Source/sourcekitten/IndexCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,19 +17,21 @@ struct IndexCommand: CommandProtocol {

struct Options: OptionsProtocol {
let file: String
let compilerargs: String
let compilerargs: [String]

static func create(file: String) -> (_ compilerargs: String) -> Options {
return { compilerargs in
static func create(file: String) -> (_: Bool) -> (_ compilerargs: [String]) -> Options {
return { _ in { compilerargs in
self.init(file: file, compilerargs: compilerargs)
}
}}
}

static func evaluate(_ mode: CommandMode) -> Result<Options, CommandantError<SourceKittenError>> {
return create
<*> mode <| Option(key: "file", defaultValue: "", usage: "relative or absolute path of Swift file to index")
<*> mode <| Option(key: "compilerargs", defaultValue: "",
usage: "Compiler arguments to pass to SourceKit. This must be specified following the '--'")
<*> mode <| Switch(key: "compilerargs",
usage: "It remains for compatibility with older versions. It is simply ignored.")
<*> mode <| Argument(defaultValue: [],
usage: "Compiler arguments to pass to SourceKit. This must be specified following the '--'")
}
}

Expand All @@ -38,7 +40,7 @@ struct IndexCommand: CommandProtocol {
return .failure(.invalidArgument(description: "file must be set when calling index"))
}
let absoluteFile = options.file.bridge().absolutePathRepresentation()
let request = Request.index(file: absoluteFile, arguments: options.compilerargs.components(separatedBy: " "))
let request = Request.index(file: absoluteFile, arguments: options.compilerargs)
do {
print(toJSON(toNSDictionary(try request.send())))
return .success(())
Expand Down

0 comments on commit 4d3c277

Please sign in to comment.