Skip to content

Dependency injection (DI) & Inversion of Control (IoC) command line tool for Swift based on code generation

License

Notifications You must be signed in to change notification settings

apleshkov/saber

Repository files navigation

Saber

Dependency Injection (DI) / Inversion of Control (IoC) command line tool for Swift based on code generation.

Saber requires no frameworks, just parses sources (via SourceKitten), finds annotations and generates containers.

Documentation

Please, see wiki and examples.

Installation

Building on macOS requires Xcode w/ Swift 4.2 and Swift Package Manager.

$ mint install apleshkov/saber

Homebrew

TODO (not notable enough yet)

Make

Clone & run make install in the root directory of this project.

Run make uninstall to uninstall.

Usage

$ 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

sources

Saber traverses swift-files --from recursively and generates container classes to --out.

Example: 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)

xcodeproj (on macOS only)

Saber parses Xcode project at --path, traverses enumerated --targets and generates container classes to --out. The main difference from the sources command is an ability to work with Swift modules.

Example: 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)

Configuration

Provide it via --config as text or file:

# 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

Development

Xcode: clone, run make xcodeproj and then open a generated Saber.xcodeproj. Use make docker_linux_test to test on Linux inside a docker container.

Linux: make clean, make build and make test

License

MIT

About

Dependency injection (DI) & Inversion of Control (IoC) command line tool for Swift based on code generation

Topics

Resources

License

Stars

Watchers

Forks

Packages

No packages published