Skip to content
This repository has been archived by the owner on Oct 17, 2021. It is now read-only.

SwiftDocOrg/GitConfig

Repository files navigation

GitConfig

CI

A Swift library for parsing Git configuration files.

Requirements

  • Swift 5.3+

Usage

let example = #"""
# This is an example .git/config file
[core]
    repositoryformatversion = 0
    filemode = true
    bare = false

    # equivalent to "blank-at-eol,blank-at-eof"
    whitespace = trailing-space

# [unused]
#   should-be-parsed = false

[remote "origin"]
    url = [email protected]:SwiftDocOrg/GitConfig.git
    fetch = +refs/heads/*:refs/remotes/origin/*
    gh-resolved = base
"""#

let configuration = try Configuration(example)
configuration.sections.count // 2

// Sections are stored in declaration order
// and can be retrieved by array index or by name
configuration["core"] == configuration.sections[0] // true

configuration["core"]?["repositoryformatversion"] // 0
configuration["core"]?["filemode"] // true
configuration["core"]?["bare"] // "trailing-space"
configuration["core"]?["whitespace"] // false
configuration["core"]?["undefined"] // nil

let remote = configuration["remote \"origin\""]
remote["url"] // "[email protected]:SwiftDocOrg/GitConfig.git"
remote["fetch"] // "+refs/heads/*:refs/remotes/origin/*"
remote["gh-resolved"] // "base"

Installation

Swift Package Manager

Add the GitConfig package to your target dependencies in Package.swift:

import PackageDescription

let package = Package(
  name: "YourProject",
  dependencies: [
    .package(
        url: "https://github.com/SwiftDocOrg/GitConfig",
        from: "0.0.1"
    ),
  ]
)

Add GitConfig as a dependency to your target(s):

targets: [
.target(
    name: "YourTarget",
    dependencies: ["GitConfig"]),

License

MIT

Contact

Mattt (@mattt)

About

No description, website, or topics provided.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages