基于代码生成的 Swift 依赖注入 (DI) / 控制反转 (IoC) 命令行工具。
Saber 不需要任何框架,仅通过 SourceKitten 解析源代码,查找 注解 并生成 容器。
在 macOS 上构建需要 Xcode w/ Swift 4.2 和 Swift Package Manager。
$ mint install apleshkov/saber
TODO (还不够显著)
克隆 & 在此项目的根目录下运行 make install
。
运行 make uninstall
来卸载。
$ saber help
Available commands:
help Display general or command-specific help
sources Generate containers from sources
version Print current version
xcodeproj Generate containers from Xcode project
Saber 会递归地遍历 --from
指定的 swift 文件,并将容器类生成到 --out
指定的目录。
示例: saber sources --workDir . --from Sources --out Sources/Saber
$ saber help sources
Generate containers from sources
[--workDir (string)]
Working directory (optional)
[--from (string)]
Directory with sources (is relative to --workDir if any)
[--out (string)]
Output directory (is relative to --workDir if any)
[--config (string)]
Path to *.yml or YAML text (optional)
[--log (string)]
Could be 'info' (by default) or 'debug' (optional)
Saber 解析 --path
指定的 Xcode 项目,遍历枚举的 --targets
,并将容器类生成到 --out
指定的目录。 与 sources
命令的主要区别在于它能够处理 Swift 模块。
示例: saber xcodeproj --workDir . --path MyProject.xcodeproj --targets Target1,Target2 --out Sources/Saber
$ saber help xcodeproj
Generate containers from Xcode project
[--workDir (string)]
Working directory (optional)
[--path (string)]
Path to *.xcodeproj (is relative to --workDir if any)
[--targets (string)]
Comma-separated list of project target names
[--out (string)]
Output directory (is relative to --workDir if any)
[--config (string)]
Path to *.yml or YAML text (optional)
[--log (string)]
Could be 'info' (by default) or 'debug' (optional)
通过 --config
以文本或文件形式提供配置
# Access level for generated classes (internal by default)
accessLevel: internal # public, open, ...
# Identation for generated files (4 spaces by default)
indentation:
type: space # or tab
size: 4
# Lazy typealias (see wiki; none by default)
lazyTypealias: LazyInjection
Xcode: 克隆,运行 make xcodeproj
,然后打开生成的 Saber.xcodeproj
。使用 make docker_linux_test
在 docker 容器中进行 Linux 测试。
Linux: make clean
, make build
和 make test
MIT