SwiftLibrary 旨在成为在 Swift 生态系统中搜索软件包的最快捷方式。按照设计,Swift 从任何 git 仓库拉取依赖,其中大部分托管在 GitHub 上,但分布在成千上万的用户中。这种方式在使用上非常方便,但在易用性的同时,也确实缺乏可发现性。
幸运的是,像 swiftpm.co 这样的项目(非常感谢 Dave Verwer!)存在,它是一个相对较新且不断增长的 Swift 软件包索引。使用 SwiftLibrary,您可以直接从 CLI 搜索该索引,并快速找到您正在寻找的软件包。
$ brew tap kiliankoe/formulae
$ brew install swiftlibrary
SwiftLibrary 方便地安装为 swift-library
,这使您可以像调用 swift 本身的子命令一样调用它,例如 swift library ...
。 请参阅下面的用法示例以了解更多信息。
您当然也可以手动安装 SwiftLibrary。
$ git clone https://github.com/kiliankoe/SwiftLibrary
$ cd SwiftLibrary
$ swift build -c release
$ cp .build/release/swift-library /usr/local/bin/swift-library
SwiftLibrary 公开了一些命令。 它们的用法最好用一些例子来展示。
$ swift library search yaml
- behrang/YamlSwift
https://github.com/behrang/YamlSwift.git
Load YAML and JSON documents using Swift
- jpsim/Yams
https://github.com/jpsim/Yams.git
A Sweet and Swifty YAML parser.
...
$ swift library info yams
jpsim/Yams 2.0.0
A Sweet and Swifty YAML parser.
407 stargazers
407 watchers
Licensed under MIT.
Supports Swift 5, 4.2, 4.
Last released: 4 months ago.
Contains 1 library/libraries.
Contains 0 executable(s).
您还可以运行 swift library home yams
,以在您的浏览器中直接打开特定软件包的主页。 如果您使用过 homebrew,您可能知道此功能。
$ swift library add yams
Your clipboard has been updated, just add it to your package manifest.
目前,SwiftLibrary 不会直接编辑您的清单文件,但会将您需要的所有内容添加到您的剪贴板,以便您可以将其直接粘贴到您的软件包清单中。
也可以添加特定版本或其他要求。 您只需在软件包末尾添加 @requirement
。 如果您使用过 npm,您可能对这种语法感到熟悉。 以下所有方式均有效。
$ swift library add yams@2.0.0
$ swift library add yams@tag:2.0.0 # same as above
$ swift library add yams@version:2.0.0 # same as above
$ swift library add yams@branch:master
$ swift library add yams@revision:c947a30
$ swift library add yams@commit:c947a30 # same as above
为了方便起见,还提供了一种简写语法来表示可用的命令。 您可以使用 s
代替 search
,i
代替 info
,h
代替 home
,以及 a
或 +
代替 add
。
您遇到任何问题或有疑问吗? 请随时 提出问题 或在 Twitter 上找到我 @kiliankoe。