Skip to content

Commit

Permalink
No color flag and Lux updated to 0.3.6
Browse files Browse the repository at this point in the history
  • Loading branch information
ABridoux committed Jul 4, 2020
1 parent 99196da commit a558ffc
Show file tree
Hide file tree
Showing 12 changed files with 66 additions and 42 deletions.
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": "8174cedcd6542b59b9e88b577ba87f10fa1ab312",
"version": "0.3.5"
"revision": "c0b65dceb8e36335874c412c9611fdac021a57af",
"version": "0.3.6"
}
},
{
Expand Down
9 changes: 6 additions & 3 deletions Sources/ScoutCLT/Add/AddCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct AddCommand: ParsableCommand {
@Flag(name: [.short, .long], inversion: .prefixedNo, help: "Output the modified data")
var verbose = false

@Flag(name: [.long], inversion: .prefixedNo, help: "Colorise the ouput")
var color = true

func run() throws {

do {
Expand All @@ -45,17 +48,17 @@ struct AddCommand: ParsableCommand {
if var json = try? PathExplorerFactory.make(Json.self, from: data) {

try add(pathsAndValues, to: &json)
try ScoutCommand.output(output, dataWith: json, verbose: verbose)
try ScoutCommand.output(output, dataWith: json, verbose: verbose, colorise: color)

} else if var plist = try? PathExplorerFactory.make(Plist.self, from: data) {

try add(pathsAndValues, to: &plist)
try ScoutCommand.output(output, dataWith: plist, verbose: verbose)
try ScoutCommand.output(output, dataWith: plist, verbose: verbose, colorise: color)

} else if var xml = try? PathExplorerFactory.make(Xml.self, from: data) {

try add(pathsAndValues, to: &xml)
try ScoutCommand.output(output, dataWith: xml, verbose: verbose)
try ScoutCommand.output(output, dataWith: xml, verbose: verbose, colorise: color)

} else {
if let filePath = inputFilePath {
Expand Down
4 changes: 3 additions & 1 deletion Sources/ScoutCLT/Add/AddDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,8 +48,10 @@ struct AddDocumentation: Documentation {
Notes
-----
- You add delete multiple values in one command
- You can add multiple values in one command
- Specify the \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "-v")) flag to see the modified data
- Deactivate the output colorization with \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "--no-color")).
Useful if you encounter slowdowns when dealing with large files although it is not recommended not ouput large files in the terminal.
- All the keys which do not exist in the path will be created
- Enclose the value with slash signs to force the value as a string: /valueAsString/ (Plist, Json)
Expand Down
34 changes: 17 additions & 17 deletions Sources/ScoutCLT/ColorDelegates/ColorFile.swift
Original file line number Diff line number Diff line change
@@ -1,29 +1,29 @@
struct JsonColors: Codable {
var punctuation: Int? = nil
var keyName: Int? = nil
var keyValue: Int? = nil
var punctuation: Int?
var keyName: Int?
var keyValue: Int?
}

struct PlistColors: Codable {
var tag: Int? = nil
var keyName: Int? = nil
var keyValue: Int? = nil
var header: Int? = nil
var comment: Int? = nil
var tag: Int?
var keyName: Int?
var keyValue: Int?
var header: Int?
var comment: Int?
}

struct XmlColors: Codable {
var punctuation: Int? = nil
var openingTag: Int? = nil
var closingTag: Int? = nil
var key: Int? = nil
var header: Int? = nil
var comment: Int? = nil
var punctuation: Int?
var openingTag: Int?
var closingTag: Int?
var key: Int?
var header: Int?
var comment: Int?
}

/// Plist file to specify custom colors
struct ColorFile: Codable {
var json: JsonColors? = nil
var plist: PlistColors? = nil
var xml: XmlColors? = nil
var json: JsonColors?
var plist: PlistColors?
var xml: XmlColors?
}
9 changes: 6 additions & 3 deletions Sources/ScoutCLT/Delete/DeleteCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ struct DeleteCommand: ParsableCommand {
@Flag(name: [.short, .long], inversion: .prefixedNo, help: "Output the modified data")
var verbose = false

@Flag(name: [.long], inversion: .prefixedNo, help: "Colorise the ouput")
var color = true

// MARK: - Functions

func run() throws {
Expand All @@ -52,17 +55,17 @@ struct DeleteCommand: ParsableCommand {
if var json = try? PathExplorerFactory.make(Json.self, from: data) {

try readingPaths.forEach { try json.delete($0) }
try ScoutCommand.output(output, dataWith: json, verbose: verbose)
try ScoutCommand.output(output, dataWith: json, verbose: verbose, colorise: color)

} else if var plist = try? PathExplorerFactory.make(Plist.self, from: data) {

try readingPaths.forEach { try plist.delete($0) }
try ScoutCommand.output(output, dataWith: plist, verbose: verbose)
try ScoutCommand.output(output, dataWith: plist, verbose: verbose, colorise: color)

} else if var xml = try? PathExplorerFactory.make(Xml.self, from: data) {

try readingPaths.forEach { try xml.delete($0) }
try ScoutCommand.output(output, dataWith: xml, verbose: verbose)
try ScoutCommand.output(output, dataWith: xml, verbose: verbose, colorise: color)

} else {
if let filePath = inputFilePath {
Expand Down
7 changes: 5 additions & 2 deletions Sources/ScoutCLT/Delete/DeleteDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -44,14 +44,17 @@ struct DeleteDocumentation: Documentation {
-----
- If the path is invalid, the program will return an error
- You can delete multiple values in one command
- When accessing an array value by its index, use the index -1 to access to the last element
- Specify the \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "-v")) flag to see the modified data
- Deactivate the output colorization with \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "--no-color")).
Useful if you encounter slowdowns when dealing with large files although it is not recommended not ouput large files in the terminal.
- When accessing an array value by its index, use the index -1 to access to the last element
Examples
--------
JSON file
\(jsonInjector.inject(in: jsonExample))
\(examplesText(from: examples))
Expand Down
2 changes: 0 additions & 2 deletions Sources/ScoutCLT/Main/DocCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,6 @@ import Lux
private let jsonInjector = JSONInjector(type: .terminal)
private let zshInjector = ZshInjector(type: .terminal)


private let jsonExample =
"""
{
Expand Down Expand Up @@ -112,7 +111,6 @@ Adding
"""


struct DocCommand: ParsableCommand {
static let configuration = CommandConfiguration(
commandName: "doc",
Expand Down
8 changes: 4 additions & 4 deletions Sources/ScoutCLT/Main/ScoutCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,7 @@ struct ScoutCommand: ParsableCommand {
VersionCommand.self],
defaultSubcommand: ReadCommand.self)

static func output<T: PathExplorer>(_ output: String?, dataWith pathExplorer: T, verbose: Bool) throws {
static func output<T: PathExplorer>(_ output: String?, dataWith pathExplorer: T, verbose: Bool, colorise: Bool) throws {
if let output = output?.replacingTilde {
let fm = FileManager.default
try fm.createFile(atPath: output, contents: pathExplorer.exportData(), attributes: nil)
Expand Down Expand Up @@ -65,11 +65,11 @@ struct ScoutCommand: ParsableCommand {
injector = xmlInjector
}

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

if verbose {
print(highlightedOutput)
print(output)
}
}

Expand Down
10 changes: 9 additions & 1 deletion Sources/ScoutCLT/Read/ReadCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ struct ReadCommand: ParsableCommand {
@Option(name: [.short, .customLong("input")], help: "A file path from which to read the data")
var inputFilePath: String?

@Flag(name: [.long], inversion: .prefixedNo, help: "Colorise the ouput")
var color = true

// MARK: - Functions

func run() throws {
Expand All @@ -44,7 +47,7 @@ struct ReadCommand: ParsableCommand {
throw RuntimeError.noValueAt(path: readingPath.description)
}

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

} catch let error as PathExplorerError {
Expand All @@ -53,6 +56,11 @@ struct ReadCommand: ParsableCommand {
}
}

/// - Parameters:
/// - path: The path of the value to output
/// - data: The data where to search for the value
/// - Throws: If the path is invalid or the values does not exist
/// - Returns: The value, and the corresponding
func readValue(at path: Path, in data: Data) throws -> (value: String, injector: TextInjector) {

var injector: TextInjector
Expand Down
4 changes: 3 additions & 1 deletion Sources/ScoutCLT/Read/ReadDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,12 +46,14 @@ struct ReadDocumentation: Documentation {
- If the path is invalid, the program will return an error
- Enclose the value with sharp signs to change the key name: #keyName#
- When accessing an array value by its index, use the index -1 to access to the last element
- Deactivate the output colorization with \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "--no-color")).
Useful if you encounter slowdowns when dealing with large files although it is not recommended not ouput large files in the terminal.
Examples
--------
JSON file
\(jsonInjector.inject(in: jsonExample))
\(examplesText(from: examples))
Expand Down
9 changes: 6 additions & 3 deletions Sources/ScoutCLT/Set/SetCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -23,6 +23,9 @@ struct SetCommand: ParsableCommand {
@Flag(name: [.short, .long], inversion: .prefixedNo, help: "Output the modified data")
var verbose = false

@Flag(name: [.long], inversion: .prefixedNo, help: "Colorise the ouput")
var color = true

func run() throws {

do {
Expand All @@ -45,17 +48,17 @@ struct SetCommand: ParsableCommand {
if var json = try? PathExplorerFactory.make(Json.self, from: data) {

try set(pathsAndValues, in: &json)
try ScoutCommand.output(output, dataWith: json, verbose: verbose)
try ScoutCommand.output(output, dataWith: json, verbose: verbose, colorise: color)

} else if var plist = try? PathExplorerFactory.make(Plist.self, from: data) {

try set(pathsAndValues, in: &plist)
try ScoutCommand.output(output, dataWith: plist, verbose: verbose)
try ScoutCommand.output(output, dataWith: plist, verbose: verbose, colorise: color)

} else if var xml = try? PathExplorerFactory.make(Xml.self, from: data) {

try set(pathsAndValues, in: &xml)
try ScoutCommand.output(output, dataWith: xml, verbose: verbose)
try ScoutCommand.output(output, dataWith: xml, verbose: verbose, colorise: color)

} else {
if let filePath = inputFilePath {
Expand Down
8 changes: 5 additions & 3 deletions Sources/ScoutCLT/Set/SetDocumentation.swift
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,7 @@ struct SetDocumentation: Documentation {

private static let examples = [(#"`scout set "urlset[1].changefreq=yearly"`"#, #"will change the second url #changefreq# key value to "yearly""#),
(#"`scout set "urlset[0].priority"=2.0`"#, #"will change the first url #priority# key value to 2.0"#),
(#"`scout set "urlset[1].changefreq=yearly"` "urlset[0].priority=2.0"`"#, """
(#"`scout set "urlset[1].changefreq=yearly"` "urlset[0].priority=2.0"`"#, """
will change both the second url #changefreq# key value to "yearly"
and the first url #priority# key value to 2.0
"""),
Expand All @@ -45,7 +45,9 @@ struct SetDocumentation: Documentation {
-----
- You can set multiple values in one command.
- Specify the \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "-v")) flag to see the modified data
- Deactivate the output colorization with \(zshInjector.delegate.inject(.optionNameOrFlag, in: .terminal, "--no-color")).
Useful if you encounter slowdowns when dealing with large files although it is not recommended not ouput large files in the terminal.
- If the path is invalid, the program will return an error
- Enclose the value with sharp signs to change the key name: #keyName#
- Enclose the value with slash signs to force the value as a string: /valueAsString/ (Plist, Json)
Expand All @@ -58,7 +60,7 @@ struct SetDocumentation: Documentation {
--------
Xml file
\(xmlInjector.inject(in: xmlExample))
\(examplesText(from: examples))
Expand Down

0 comments on commit a558ffc

Please sign in to comment.