mirror of
https://github.com/Sunnyyoung/WeChatTweak-macOS.git
synced 2025-12-16 17:15:41 +08:00
command: optimize with option group
This commit is contained in:
parent
0682644327
commit
ac9b1575de
|
|
@ -9,8 +9,6 @@ import Foundation
|
||||||
import MachO
|
import MachO
|
||||||
|
|
||||||
struct Config: Decodable {
|
struct Config: Decodable {
|
||||||
static let `default` = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/master/config.json")!
|
|
||||||
|
|
||||||
enum Arch: String, Decodable {
|
enum Arch: String, Decodable {
|
||||||
case arm64
|
case arm64
|
||||||
case x86_64
|
case x86_64
|
||||||
|
|
@ -83,7 +81,7 @@ struct Config: Decodable {
|
||||||
let version: String
|
let version: String
|
||||||
let targets: [Target]
|
let targets: [Target]
|
||||||
|
|
||||||
static func load(url: URL = Self.default) async throws -> [Config] {
|
static func load(url: URL) async throws -> [Config] {
|
||||||
if url.isFileURL {
|
if url.isFileURL {
|
||||||
return try JSONDecoder().decode(
|
return try JSONDecoder().decode(
|
||||||
[Config].self,
|
[Config].self,
|
||||||
|
|
|
||||||
|
|
@ -13,8 +13,14 @@ extension Tweak {
|
||||||
struct Versions: AsyncParsableCommand {
|
struct Versions: AsyncParsableCommand {
|
||||||
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
|
||||||
|
|
||||||
|
@OptionGroup
|
||||||
|
var options: Tweak.Options
|
||||||
|
|
||||||
mutating func run() async throws {
|
mutating func run() async throws {
|
||||||
try await Config.load().forEach({ print($0.version) })
|
print("------ Current version ------")
|
||||||
|
print(try await Command.version(app: options.app) ?? "unknown")
|
||||||
|
print("------ Supported versions ------")
|
||||||
|
try await Config.load(url: options.config).forEach({ print($0.version) })
|
||||||
Darwin.exit(EXIT_SUCCESS)
|
Darwin.exit(EXIT_SUCCESS)
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
@ -23,6 +29,43 @@ extension Tweak {
|
||||||
// MARK: Patch
|
// MARK: Patch
|
||||||
extension Tweak {
|
extension Tweak {
|
||||||
struct Patch: AsyncParsableCommand {
|
struct Patch: AsyncParsableCommand {
|
||||||
|
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
||||||
|
|
||||||
|
@OptionGroup
|
||||||
|
var options: Tweak.Options
|
||||||
|
|
||||||
|
mutating func run() async throws {
|
||||||
|
print("------ Version ------")
|
||||||
|
let version = try await Command.version(app: options.app)
|
||||||
|
print("WeChat version: \(version ?? "unknown")")
|
||||||
|
|
||||||
|
print("------ Config ------")
|
||||||
|
guard let config = (try await Config.load(url: options.config)).first(where: { $0.version == version }) else {
|
||||||
|
throw Error.unsupportedVersion
|
||||||
|
}
|
||||||
|
print("Matched config: \(config)")
|
||||||
|
|
||||||
|
print("------ Patch ------")
|
||||||
|
try await Command.patch(
|
||||||
|
app: options.app,
|
||||||
|
config: config
|
||||||
|
)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
print("------ Resign ------")
|
||||||
|
try await Command.resign(
|
||||||
|
app: options.app
|
||||||
|
)
|
||||||
|
print("Done!")
|
||||||
|
|
||||||
|
Darwin.exit(EXIT_SUCCESS)
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
|
}
|
||||||
|
|
||||||
|
// MARK: Tweak
|
||||||
|
struct Tweak: AsyncParsableCommand {
|
||||||
enum Error: LocalizedError {
|
enum Error: LocalizedError {
|
||||||
case invalidApp
|
case invalidApp
|
||||||
case invalidConfig
|
case invalidConfig
|
||||||
|
|
@ -43,8 +86,7 @@ extension Tweak {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
static let configuration = CommandConfiguration(abstract: "Patch WeChat.app")
|
struct Options: ParsableArguments {
|
||||||
|
|
||||||
@Option(
|
@Option(
|
||||||
name: .shortAndLong,
|
name: .shortAndLong,
|
||||||
help: "Path of WeChat.app",
|
help: "Path of WeChat.app",
|
||||||
|
|
@ -71,42 +113,9 @@ extension Tweak {
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
)
|
)
|
||||||
var config: URL = Config.default
|
var config: URL = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/master/config.json")!
|
||||||
|
|
||||||
mutating func run() async throws {
|
|
||||||
print("------ Version ------")
|
|
||||||
guard let version = try await Command.version(app: self.app) else {
|
|
||||||
throw Error.invalidVersion
|
|
||||||
}
|
|
||||||
print("WeChat version: \(version)")
|
|
||||||
|
|
||||||
print("------ Config ------")
|
|
||||||
guard let config = (try await Config.load()).first(where: { $0.version == version }) else {
|
|
||||||
throw Error.unsupportedVersion
|
|
||||||
}
|
|
||||||
print("Matched config: \(config)")
|
|
||||||
|
|
||||||
print("------ Patch ------")
|
|
||||||
try await Command.patch(
|
|
||||||
app: self.app,
|
|
||||||
config: config
|
|
||||||
)
|
|
||||||
print("Done!")
|
|
||||||
|
|
||||||
print("------ Resign ------")
|
|
||||||
try await Command.resign(
|
|
||||||
app: self.app
|
|
||||||
)
|
|
||||||
print("Done!")
|
|
||||||
|
|
||||||
Darwin.exit(EXIT_SUCCESS)
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
|
||||||
|
|
||||||
// MARK: Tweak
|
|
||||||
struct Tweak: AsyncParsableCommand {
|
|
||||||
static let configuration = CommandConfiguration(
|
static let configuration = CommandConfiguration(
|
||||||
commandName: "wechattweak",
|
commandName: "wechattweak",
|
||||||
abstract: "A command-line tool for tweaking WeChat.",
|
abstract: "A command-line tool for tweaking WeChat.",
|
||||||
|
|
|
||||||
Loading…
Reference in New Issue
Block a user