refactor CLI
This commit is contained in:
@@ -1,7 +1,7 @@
|
||||
import ArgumentParser
|
||||
|
||||
extension phbar {
|
||||
struct refresh: ParsableCommand {
|
||||
extension PHBar {
|
||||
struct Refresh: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "refresh",
|
||||
abstract: "Refresh the running status bar."
|
||||
@@ -2,8 +2,8 @@ import AppKit
|
||||
import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
extension phbar {
|
||||
struct start: ParsableCommand {
|
||||
extension PHBar {
|
||||
struct Start: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "start",
|
||||
abstract: "Start the status bar.",
|
||||
@@ -19,7 +19,7 @@ extension PHBlock {
|
||||
|
||||
let setFile = base.appending(path: "blocks").appending(path: "\(blocks).toml")
|
||||
guard FileManager.default.fileExists(atPath: setFile.relativePath) else {
|
||||
throw phbar.Error("Failed to load blocks '\(blocks)'")
|
||||
throw PHBar.Error("Failed to load blocks '\(blocks)'")
|
||||
}
|
||||
return try load(from: setFile)
|
||||
}
|
||||
@@ -30,11 +30,11 @@ extension PHBlock {
|
||||
do {
|
||||
let data = try Data(contentsOf: url)
|
||||
guard let contents = String(data: data, encoding: .utf8), !contents.isEmpty else {
|
||||
throw phbar.Error("the file is empty")
|
||||
throw PHBar.Error("the file is empty")
|
||||
}
|
||||
return try load(from: contents)
|
||||
} catch {
|
||||
throw phbar.Error("Failed to load blocks file", underlyingError: error)
|
||||
throw PHBar.Error("Failed to load blocks file", underlyingError: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -46,7 +46,7 @@ extension PHBlock {
|
||||
let wrapper = try decoder.decode(PHBlock.Wrapper.self, from: contents)
|
||||
return wrapper.blocks
|
||||
} catch {
|
||||
throw phbar.Error("Failed to parse blocks file", underlyingError: error)
|
||||
throw PHBar.Error("Failed to parse blocks file", underlyingError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -24,7 +24,7 @@ extension PHConfig {
|
||||
withExtension: "toml"
|
||||
)?.resolvingSymlinksInPath()
|
||||
else {
|
||||
throw phbar.Error("Failed to load config file")
|
||||
throw PHBar.Error("Failed to load config file")
|
||||
}
|
||||
return try load(from: defaultConfig)
|
||||
}
|
||||
@@ -35,7 +35,7 @@ extension PHConfig {
|
||||
guard let data = try? Data(contentsOf: url),
|
||||
let contents = String(data: data, encoding: .utf8)
|
||||
else {
|
||||
throw phbar.Error("Failed to load config file")
|
||||
throw PHBar.Error("Failed to load config file")
|
||||
}
|
||||
|
||||
return try load(from: contents)
|
||||
@@ -53,7 +53,7 @@ extension PHConfig {
|
||||
// resolve the same set.
|
||||
return config.resolvingEnv()
|
||||
} catch {
|
||||
throw phbar.Error("Failed to parse config file", underlyingError: error)
|
||||
throw PHBar.Error("Failed to parse config file", underlyingError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -28,7 +28,7 @@ extension PHTheme {
|
||||
withExtension: "toml"
|
||||
)?.resolvingSymlinksInPath()
|
||||
else {
|
||||
throw phbar.Error("Failed to load theme file")
|
||||
throw PHBar.Error("Failed to load theme file")
|
||||
}
|
||||
return try load(from: defaultConfig, environment: .process)
|
||||
}
|
||||
@@ -39,11 +39,11 @@ extension PHTheme {
|
||||
do {
|
||||
let data = try Data(contentsOf: url)
|
||||
guard let contents = String(data: data, encoding: .utf8), !contents.isEmpty else {
|
||||
throw phbar.Error("the file is empty")
|
||||
throw PHBar.Error("the file is empty")
|
||||
}
|
||||
return try load(from: contents, environment: environment)
|
||||
} catch {
|
||||
throw phbar.Error("Failed to load theme file", underlyingError: error)
|
||||
throw PHBar.Error("Failed to load theme file", underlyingError: error)
|
||||
}
|
||||
}
|
||||
|
||||
@@ -55,7 +55,7 @@ extension PHTheme {
|
||||
decoder.userInfo[PHEnvironment.userInfoKey] = environment
|
||||
return try decoder.decode(PHTheme.self, from: contents)
|
||||
} catch {
|
||||
throw phbar.Error("Failed to parse theme file", underlyingError: error)
|
||||
throw PHBar.Error("Failed to parse theme file", underlyingError: error)
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,7 +8,7 @@ import ArgumentParser
|
||||
import Foundation
|
||||
|
||||
@main
|
||||
struct phbar: ParsableCommand {
|
||||
struct PHBar: ParsableCommand {
|
||||
static let configuration = CommandConfiguration(
|
||||
commandName: "phbar",
|
||||
abstract: "Modular status bar for macOS.",
|
||||
@@ -39,11 +39,11 @@ struct phbar: ParsableCommand {
|
||||
the same command to start the bar automatically at login.
|
||||
""",
|
||||
version: "1.0.0",
|
||||
subcommands: [start.self, refresh.self]
|
||||
subcommands: [Start.self, Refresh.self]
|
||||
)
|
||||
}
|
||||
|
||||
extension phbar {
|
||||
extension PHBar {
|
||||
struct Error: LocalizedError {
|
||||
let message: String
|
||||
let underlyingError: Swift.Error?
|
||||
@@ -7,7 +7,7 @@ import Testing
|
||||
// MARK: - Refresh command
|
||||
|
||||
@Test func refreshCommandConfigurationIsCorrect() async throws {
|
||||
let config = phbar.refresh.configuration
|
||||
let config = PHBar.Refresh.configuration
|
||||
#expect(config.commandName == "refresh")
|
||||
#expect(config.abstract == "Refresh the running status bar.")
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user