This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutating func run() throws { | |
// 1 | |
let filePathWithExtension = "\(filePath)\(fileExtension)" | |
// 2 | |
try? note.write(toFile: filePathWithExtension, atomically: true, encoding: .utf8) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
@Option(name: [.customLong("file")], help: "The file path to write the note to.") | |
var filePath: String | |
// 2 | |
@Argument(help: "The note to write to file.") | |
var note: String | |
// 3 | |
@Flag(name: .shortAndLong, help: "Overrides existing file.") |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct CLINotes: ParsableCommand { | |
// 1 | |
static let configuration: CommandConfiguration = CommandConfiguration( | |
commandName: "clinotes", | |
abstract: "Manage your notes from the command line", | |
discussion: "Create your nodes from the command-line. Each file generated with this tool has the extension \(fileExtension).", | |
subcommands: [Write.self] | |
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
mutating func run() throws { | |
let filePathWithExtension = "\(filePath)\(fileExtension)" | |
// 1 | |
do { | |
try note.write(toFile: filePathWithExtension, atomically: true, encoding: .utf8) | |
} catch { | |
// 2 | |
throw RuntimeError("Couldn't write to `\(filePath)`!") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
func validate() throws { | |
let filePathWithExtension = "\(filePath)\(fileExtension)" | |
// 2 | |
if FileManager.default.fileExists(atPath: filePathWithExtension) && force == false { | |
// 3 | |
throw ValidationError("Given file already exists. To override it, please add `--force`.") | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
struct RuntimeError: Error, CustomStringConvertible { | |
var description: String | |
init(_ description: String) { | |
self.description = description | |
} | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import ArgumentParser | |
import Foundation | |
// 1 | |
struct CLINotes: ParsableCommand { | |
// 2 | |
static let fileExtension = ".clinote" | |
// 3 |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// swift-tools-version: 5.5 | |
// The swift-tools-version declares the minimum version of Swift required to build this package. | |
import PackageDescription | |
let package = Package( | |
name: "CLINotes", | |
products: [ | |
.executable( | |
name: "CLINotes", |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// 1 | |
enum Category: String { | |
case UIKit, SwiftUI | |
// 2 | |
static var order = [Category.UIKit.rawValue, Category.SwiftUI.rawValue] | |
} | |
// 3 | |
private var categoricalXAxis: AXCategoricalDataAxisDescriptor { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
private var series: [AXDataSeriesDescriptor] { | |
let yValuesSeries1 = [4.0, 5.0, 6.0, 3.0, 2.0, 1.0, 1.0, 3.0, 6.0, 9.0] | |
let dataPointsSeries1 = yValuesSeries1.enumerated().map { index, yValue in | |
AXDataPoint(x: Double(index), y: yValue) | |
} | |
return [ | |
AXDataSeriesDescriptor( | |
name: "Data Series 1", |
NewerOlder