Skip to content

Commit

Permalink
Merge pull request #77 from ABridoux/release/release-1.2.3
Browse files Browse the repository at this point in the history
Release 1.2.3
  • Loading branch information
ABridoux authored Jul 6, 2020
2 parents 4cfbf67 + 97736a6 commit 870facf
Show file tree
Hide file tree
Showing 24 changed files with 156 additions and 187 deletions.
9 changes: 9 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -3,6 +3,15 @@
All notable changes to this project will be documented in this file. `Scout` adheres to [Semantic Versioning](http://semver.org).

---
## [1.2.3](https://github.com/ABridoux/scout/tree/1.2.3) (06/07/2020)

### Changed
- Errors now sent to the standard error ouput with an error code different from 0 [#74]
- Documentation updated [#74]

### Fixed
- JSON empty string colorisation [#72]

## [1.2.2](https://github.com/ABridoux/scout/tree/1.2.2) (04/07/2020)

### Added
Expand Down
4 changes: 2 additions & 2 deletions Package.resolved
Original file line number Diff line number Diff line change
Expand Up @@ -15,8 +15,8 @@
"repositoryURL": "https://github.com/ABridoux/lux",
"state": {
"branch": null,
"revision": "c0b65dceb8e36335874c412c9611fdac021a57af",
"version": "0.3.6"
"revision": "c433264cec4e9c8563d93d2fecb0af65e683f01d",
"version": "0.3.7"
}
},
{
Expand Down
3 changes: 3 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,9 @@ Install:<br>
<a href="https://github.com/ABridoux/scout/releases">
<img src="https://img.shields.io/badge/install-pkg%2Bzip-blue" />
</a>
<a href="#">
<img src="https://img.shields.io/github/downloads/ABridoux/scout/total">
</a>
<br/>
</p>

Expand Down
Binary file modified Resources/scout-logo.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.2.2"
public static let current = "1.2.3"
}
11 changes: 7 additions & 4 deletions Sources/Scout/Definitions/Path.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,15 +48,16 @@ public extension Path {
- note: The following separators will not work: "[", "]", "(", ")".
When using a special caracter with [regular expression](https://developer.apple.com/documentation/foundation/nsregularexpression#1965589),
it is required to quote it with "\\".

*/
init(string: String, separator: String = "\\.") throws {
var elements = [PathElement]()

let splitRegexPattern = #"\(.+\)|[^\#(separator)]+"#
let indexRegexPattern = #"(?<=\[)[0-9-]+(?=\])"#
let splitRegex = try NSRegularExpression(pattern: splitRegexPattern, options: [])
let indexRegex = try NSRegularExpression(pattern: indexRegexPattern, options: [])
let squareBracketPattern = #"\[|\]"#
let splitRegex = try NSRegularExpression(pattern: splitRegexPattern)
let indexRegex = try NSRegularExpression(pattern: indexRegexPattern)
let squareBracketRegex = try NSRegularExpression(pattern: squareBracketPattern)

let matches = splitRegex.matches(in: string)
for match in matches {
Expand Down Expand Up @@ -94,8 +95,10 @@ public extension Path {
guard let index = Int(match[indexMatch.range]) else { throw PathExplorerError.invalidPathElement(match) }
elements.append(index)
}

} else {
if squareBracketRegex.firstMatch(in: match, range: match.nsRange) != nil {
throw PathExplorerError.invalidPathElement(match)
}
elements.append(match)
}
}
Expand Down
10 changes: 5 additions & 5 deletions Sources/Scout/Definitions/PathExplorerError.swift
Original file line number Diff line number Diff line change
Expand Up @@ -21,27 +21,27 @@ public enum PathExplorerError: LocalizedError {
switch self {
case .invalidData(let type): return "Cannot intialize a \(String(describing: type)) object with the given data"
case .invalidValue(let value): return "The key value \(value) is invalid"
case .valueConversionError(let value, let type): return "Unable to convert the value \(value) to \(type)"
case .valueConversionError(let value, let type): return "Unable to convert the value `\(value)` to the type \(type)"
case .wrongValueForKey(let value, let element): return "Cannot set `\(value)` to key/index #\(element)# which is a Dictionary or an Array"

case .dictionarySubscript(let path): return "Cannot subscript the key at '\(path.description)' as it is not a Dictionary"
case .dictionarySubscript(let path): return "Cannot subscript the key at '\(path.description)' with a String as it is not a Dictionary"
case .subscriptMissingKey(let path, let key, let bestMatch):
let bestMatchString: String

if let match = bestMatch {
bestMatchString = "Best match found: \(match)"
bestMatchString = "Best match found: #\(match)#"
} else {
bestMatchString = "No best match found"
}

return "The key #\(key)# cannot be found in the Dictionary '\(path.description)'. \(bestMatchString)"

case .arraySubscript(let path): return "Cannot subscript the key at '\(path.description)' as is not an Array"
case .arraySubscript(let path): return "Cannot subscript the key at '\(path.description)' with an Integer as is not an Array"
case .subscriptWrongIndex(let path, let index, let arrayCount): return "The index #\(index)# is not within the bounds of the Array (0...\(arrayCount - 1)) at '\(path.description)'"

case .stringToDataConversionError: return "Unable to convert the input string into data"
case .dataToStringConversionError: return "Unable to convert the data to a string"
case .invalidPathElement(let element): return "Invalid path element: \(element)"
case .invalidPathElement(let element): return "Invalid path element: '\(element)'"

case .underlyingError(let description): return description
}
Expand Down
3 changes: 0 additions & 3 deletions Sources/ScoutCLT/Add/AddCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,9 +36,6 @@ struct AddCommand: ParsableCommand {
let streamInput = FileHandle.standardInput.readDataToEndOfFile()
try add(from: streamInput)
}
} catch let error as PathExplorerError {
print(error.commandLineErrorDescription)
return
}
}

Expand Down
5 changes: 0 additions & 5 deletions Sources/ScoutCLT/Command.swift

This file was deleted.

3 changes: 0 additions & 3 deletions Sources/ScoutCLT/Delete/DeleteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -43,9 +43,6 @@ struct DeleteCommand: ParsableCommand {
let streamInput = FileHandle.standardInput.readDataToEndOfFile()
try delete(from: streamInput)
}
} catch let error as PathExplorerError {
print(error.commandLineErrorDescription)
return
}
}

Expand Down
14 changes: 14 additions & 0 deletions Sources/ScoutCLT/Extensions/ArgumentHelp+Extensions.swift
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
import ArgumentParser

extension ArgumentHelp {

static var readingPath: ArgumentHelp {
ArgumentHelp(
"Path in the data where to read the key value",
discussion: """
A path is a sequence of keys separated with dots to navigate through the data.
Use a dot '.' to subscript a dictionary. For example 'parent_key.child_key'.
Use an integer enclosed by square brakets '[1]' to subscript an array. For example 'first_key.array[0].second_key'
""")
}
}
8 changes: 2 additions & 6 deletions Sources/ScoutCLT/Extensions/Path+Extensions.swift
Original file line number Diff line number Diff line change
@@ -1,14 +1,10 @@
import Scout
import ArgumentParser
import Foundation

extension Path: ExpressibleByArgument {

public init?(argument: String) {
do {
self = try Path(string: argument)
} catch {
print(error.localizedDescription)
return nil
}
try? self.init(string: argument)
}
}
38 changes: 0 additions & 38 deletions Sources/ScoutCLT/Extensions/PathExplorerError+Extensions.swift

This file was deleted.

3 changes: 2 additions & 1 deletion Sources/ScoutCLT/Extensions/String+Extensions.swift
Original file line number Diff line number Diff line change
Expand Up @@ -15,10 +15,11 @@ extension String {
static var prefix: String { "\u{001B}[" }
static var colorReset: String { "\(Self.prefix)39m" }
static var reset: String { "\(Self.prefix)0m" }
var mainColor: String { colored(with: 88) }

var bold: String { "\(Self.prefix)1;39m\(self)\(Self.prefix)22m" }
var error: String { "\(Self.colorPrefix(91))\(self)\(Self.colorReset)"}

static func colorPrefix(_ code: Int) -> String { "\(prefix)38;5;\(code)m" }

func colored(with code: Int) -> String { "\(Self.colorPrefix(code))\(self)\(Self.reset)" }
}
Loading

0 comments on commit 870facf

Please sign in to comment.