subcommand: add versions

This commit is contained in:
Sunny Young 2025-12-06 16:26:41 +08:00
parent 003643d063
commit a58f04b1d4
2 changed files with 44 additions and 39 deletions

View File

@ -1,7 +1,6 @@
# WeChatTweak # WeChatTweak
[![License](https://img.shields.io/badge/License-Apache%202.0-green.svg)](LICENSE) A command-line tool for tweaking WeChat.
[![README](https://img.shields.io/badge/Telegram-WeChatTweak-brightgreen.svg)](https://t.me/wechattweak)
## 功能 ## 功能
@ -9,15 +8,16 @@
- 阻止自动更新 - 阻止自动更新
- 客户端多开 - 客户端多开
## 安装 ## 安装&使用
```bash ```bash
# 首次安装
brew install sunnyyoung/tap/wechattweak brew install sunnyyoung/tap/wechattweak
```
## 使用 # 更新
brew upgrade wechattweak
```bash # 使用
wechattweak patch wechattweak patch
``` ```

View File

@ -8,6 +8,15 @@ import Foundation
import Dispatch import Dispatch
import ArgumentParser import ArgumentParser
struct Versions: AsyncParsableCommand {
static let configuration = CommandConfiguration(abstract: "List all supported WeChat versions")
mutating func run() async throws {
try await Config.load(from: Tweak.config).forEach({ print($0.version) })
Darwin.exit(EXIT_SUCCESS)
}
}
struct Patch: AsyncParsableCommand { struct Patch: AsyncParsableCommand {
enum Error: LocalizedError { enum Error: LocalizedError {
case invalidApp case invalidApp
@ -57,21 +66,20 @@ struct Patch: AsyncParsableCommand {
} }
} }
) )
var config: URL = URL(string: "https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/feature/2.0/config.json")! var config: URL = Tweak.config
mutating func run() async throws { mutating func run() async throws {
do {
print("------ Version ------") print("------ Version ------")
guard let version = try await Command.version(app: self.app) else { guard let version = try await Command.version(app: self.app) else {
throw Error.invalidVersion throw Error.invalidVersion
} }
print("\(version)") print("WeChat version: \(version)")
print("------ Config ------") print("------ Config ------")
guard let config = (try await Config.load(from: self.config)).first(where: { $0.version == version }) else { guard let config = (try await Config.load(from: self.config)).first(where: { $0.version == version }) else {
throw Error.unsupportedVersion throw Error.unsupportedVersion
} }
print("\(config)") print("Matched config: \(config)")
print("------ Patch ------") print("------ Patch ------")
try await Command.patch( try await Command.patch(
@ -86,13 +94,7 @@ struct Patch: AsyncParsableCommand {
) )
print("Done!") print("Done!")
print("------🎉 Done!------")
Darwin.exit(EXIT_SUCCESS) Darwin.exit(EXIT_SUCCESS)
} catch {
print("------🚨 Error------")
print("\(error.localizedDescription)")
Darwin.exit(EXIT_FAILURE)
}
} }
} }
@ -101,10 +103,13 @@ struct Tweak: AsyncParsableCommand {
commandName: "wechattweak", commandName: "wechattweak",
abstract: "A command-line tool for tweaking WeChat.", abstract: "A command-line tool for tweaking WeChat.",
subcommands: [ subcommands: [
Versions.self,
Patch.self Patch.self
], ],
defaultSubcommand: Self.self defaultSubcommand: Self.self
) )
static let config = URL(string:"https://raw.githubusercontent.com/sunnyyoung/WeChatTweak/refs/heads/feature/2.0/config.json")!
} }
Task { Task {