Skip to content

Commit

Permalink
Merge pull request #49 from ABridoux/release/release-1-1-0
Browse files Browse the repository at this point in the history
[Release] 1.1.0
  • Loading branch information
ABridoux authored May 20, 2020
2 parents 3fcece0 + 79fd2c8 commit 123e378
Show file tree
Hide file tree
Showing 7 changed files with 53 additions and 8 deletions.
13 changes: 11 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -10,13 +10,22 @@
"version": "4.5.0"
}
},
{
"package": "Lux",
"repositoryURL": "https://github.com/ABridoux/lux",
"state": {
"branch": null,
"revision": "a0bbdb1a5a03314b92533e780a50b7c90fa1e510",
"version": "0.1.1"
}
},
{
"package": "swift-argument-parser",
"repositoryURL": "https://github.com/apple/swift-argument-parser",
"state": {
"branch": null,
"revision": "35b76bf577d3cc74820f8991894ce3bcdf024ddc",
"version": "0.0.2"
"revision": "223d62adc52d51669ae2ee19bdb8b7d9fd6fcd9c",
"version": "0.0.6"
}
}
]
Expand Down
7 changes: 5 additions & 2 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,15 +20,18 @@ let package = Package(
from: "4.5.0"),
.package(
url: "https://github.com/apple/swift-argument-parser",
from: "0.0.1")
from: "0.0.1"),
.package(
url: "https://github.com/ABridoux/lux",
from: "0.1.0")
],
targets: [
.target(
name: "Scout",
dependencies: ["AEXML"]),
.target(
name: "ScoutCLT",
dependencies: ["Scout", "ArgumentParser"]),
dependencies: ["Scout", "ArgumentParser", "Lux"]),
.testTarget(
name: "ScoutTests",
dependencies: ["Scout"]),
Expand Down
12 changes: 12 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -38,6 +38,15 @@ You can use a library for each format. But I am not aware today of a library tha
### Using a generic text-processing tool
Don't get me wrong, **awk** is a wonderful tool. It can do so many things. But it is not that easy to learn. And you have to find a way to parse each different format. **Scout** is really easy to use, as we will see.

## Syntax highlighting
Starting from 1.1.0, Scout will highlight the output when reading or outputting (with the verbose flag) a dictionary or an array value. This is done with the [Lux](https://github.com/ABridoux/lux) library. You can try it with the following command.

```bash
curl --silent "https://api.github.com/repos/ABridoux/scout/releases/latest" | scout
```

![](Resources/syntax-highlight.png)

## How to use it

### Command Line
Expand Down Expand Up @@ -170,6 +179,9 @@ Given the following Json (as input stream or file with the `input` option)
]
```

`scout` will output the overall Json. No reading path means to read the overall input stream. This is useful when you just want to enjoy the syntax highlighting feature.


##### Setting
`scout set "people.Tom.hobbies[0]"=basket` will change Tom first hobby from "cooking" to "basket"

Expand Down
Binary file added Resources/syntax-highlight.png
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion Sources/Scout/Constants/Version.swift
Original file line number Diff line number Diff line change
@@ -1,3 +1,3 @@
public struct Version {
public static let current = "1.0.2"
public static let current = "1.1.0"
}
13 changes: 11 additions & 2 deletions Sources/ScoutCLT/ReadCommand.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import ArgumentParser
import Scout
import Foundation
import Lux

private let discussion =
"""
Expand Down Expand Up @@ -61,7 +62,7 @@ struct ReadCommand: ParsableCommand {
// MARK: - Properties

@Argument(help: "Path in the data where to read the key value")
var readingPath: Path
var readingPath: Path?

@Option(name: [.short, .customLong("input")], help: "A file path from which to read the data")
var inputFilePath: String?
Expand All @@ -82,15 +83,21 @@ struct ReadCommand: ParsableCommand {
func read(from data: Data) throws {
var value: String

var injector: Injector
let readingPath = self.readingPath ?? Path()

if let json = try? PathExplorerFactory.make(Json.self, from: data) {
let key = try json.get(readingPath)
value = key.stringValue != "" ? key.stringValue : key.description
injector = JSONInjector(type: .plain)
} else if let plist = try? PathExplorerFactory.make(Plist.self, from: data) {
let key = try plist.get(readingPath)
value = key.stringValue != "" ? key.stringValue : key.description
injector = PlistInjector(type: .plain)
} else if let xml = try? PathExplorerFactory.make(Xml.self, from: data) {
let key = try xml.get(readingPath)
value = key.stringValue != "" ? key.stringValue : key.description
injector = XMLEnhancedInjector(type: .plain)
} else {
if let filePath = inputFilePath {
throw RuntimeError.unknownFormat("The format of the file at \(filePath) is not recognized")
Expand All @@ -103,6 +110,8 @@ struct ReadCommand: ParsableCommand {
throw RuntimeError.noValueAt(path: readingPath.description)
}

print(value)
let output = injector.inject(in: value)
print(output)

}
}
14 changes: 13 additions & 1 deletion Sources/ScoutCLT/ScoutCommand.swift
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import Foundation
import ArgumentParser
import Scout
import Lux

private let abstract =
"""
Expand Down Expand Up @@ -95,8 +96,19 @@ struct ScoutCommand: ParsableCommand {
try fm.createFile(atPath: output, contents: pathExplorer.exportData(), attributes: nil)
}

let injector: Injector

switch pathExplorer.format {
case .json: injector = JSONInjector(type: .plain)
case .plist: injector = PlistInjector(type: .plain)
case .xml: injector = XMLEnhancedInjector(type: .plain)
}

let output = try pathExplorer.exportString()
let highlightedOutput = injector.inject(in: output)

if verbose {
print(try pathExplorer.exportString())
print(highlightedOutput)
}
}
}

0 comments on commit 123e378

Please sign in to comment.