https://github.com/zeionara/swat
A compact app for parsing files which specify several system setups in a convenient format and transforming them into a set of separate config files
https://github.com/zeionara/swat
Last synced: 3 months ago
JSON representation
A compact app for parsing files which specify several system setups in a convenient format and transforming them into a set of separate config files
- Host: GitHub
- URL: https://github.com/zeionara/swat
- Owner: zeionara
- License: apache-2.0
- Created: 2022-12-25T21:12:12.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-09T14:28:41.000Z (over 2 years ago)
- Last Synced: 2025-01-02T07:46:14.998Z (5 months ago)
- Language: Swift
- Size: 177 KB
- Stars: 0
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
[](https://skillicons.dev)
# swat
[](https://github.com/zeionara/swat/actions/workflows/test.yml)
![]()
**Sw**eet **at**tributes - a compact app for parsing files which specify several system setups in a convenient format and transforming them into a set of separate config files.
The app is an implementation of idea from [cuco](https://github.com/zeionara/cuco) python package using swift programming language.# Installation
It is recommended to utilize the swift package manager for installation. To use the app include the following statement in your `dependencies` section of the `Package.swift` like this:
```swift
dependencies: [
.package(url: "https://github.com/zeionara/swat.git", .branch("master"))
]
```And in the list of dependencies for your `target` like this:
```swift
dependencies: ["Swat"]
```Then, in your code you need to import the package and use it as you want (see file `Examples/main.swift`):
```swift
import Swatstruct Bar: ConfigWithDefaultKeys {
let foo: Int
let bar: String
}struct Foo: ConfigWithDefaultKeys, RootConfig {
let foo: Int
let bar: Barlet name: String
}let configs: [Foo] = try ConfigFactory().make(
"""
foo: 17
bar:
- foo:
- 17
- 19
bar:
- qux
- quux
- foo:
- 21
- 23
bar:
- corge
- grault
name: demo
"""
)configs.sorted{ $0.bar.foo < $1.bar.foo }.forEach{ print($0) }
```The command produces the following output:
```swift
Foo(foo: 17, bar: Examples.Bar(foo: 17, bar: "qux"), name: "demo;bar=[\"bar\": [\"qux\", \"quux\"], \"foo\": [17, 19]];bar.bar=qux;bar.foo=17")
Foo(foo: 17, bar: Examples.Bar(foo: 17, bar: "quux"), name: "demo;bar=[\"bar\": [\"qux\", \"quux\"], \"foo\": [17, 19]];bar.bar=quux;bar.foo=17")
Foo(foo: 17, bar: Examples.Bar(foo: 19, bar: "qux"), name: "demo;bar=[\"bar\": [\"qux\", \"quux\"], \"foo\": [17, 19]];bar.bar=qux;bar.foo=19")
Foo(foo: 17, bar: Examples.Bar(foo: 19, bar: "quux"), name: "demo;bar=[\"bar\": [\"qux\", \"quux\"], \"foo\": [17, 19]];bar.bar=quux;bar.foo=19")
Foo(foo: 17, bar: Examples.Bar(foo: 21, bar: "corge"), name: "demo;bar=[\"foo\": [21, 23], \"bar\": [\"corge\", \"grault\"]];bar.bar=corge;bar.foo=21")
Foo(foo: 17, bar: Examples.Bar(foo: 21, bar: "grault"), name: "demo;bar=[\"foo\": [21, 23], \"bar\": [\"corge\", \"grault\"]];bar.bar=grault;bar.foo=21")
Foo(foo: 17, bar: Examples.Bar(foo: 23, bar: "corge"), name: "demo;bar=[\"foo\": [21, 23], \"bar\": [\"corge\", \"grault\"]];bar.bar=corge;bar.foo=23")
Foo(foo: 17, bar: Examples.Bar(foo: 23, bar: "grault"), name: "demo;bar=[\"foo\": [21, 23], \"bar\": [\"corge\", \"grault\"]];bar.bar=grault;bar.foo=23")
```Generated config can be saved to local storage:
```swift
try configs.first!.write(to: Path.assets.appendingPathComponent("config.json"))
```Then you can run the following command to fetch the dependencies and build the app:
```sh
swift build
```To update the dependencies of your project invoke the following command:
```sh
swift package update
```