Swiftpack.co -  DIY-Team/RunsShellCommand as Swift Package
Swiftpack.co is a collection of thousands of indexed Swift packages. Search packages.
DIY-Team/RunsShellCommand
A library to support defining and running shell commands in swift scripts. Provides a protocol to define the command's composition and a method to execute it.
.package(url: "https://github.com/DIY-Team/RunsShellCommand.git", from: "0.0.3")

RunsShellCommand

A library to support defining and running shell commands in swift scripts. Provides a protocol to define the command's composition and a method to execute it.

Special Mention 🙏🏼

The library uses John Sundell's Shellout repo as depedency for actually running the shell commands. More info: https://github.com/JohnSundell/ShellOut.git

Usage

The library provides a protocol AnyShellCommand. Use this protocol to define the structure of your command's class, struct or enum.

Example 1:

enum GitCommand: AnyShellCommand {
    case createAndCheckoutNewBranch
    case deleteBranch
    
    var command: String {
        get { return "git" }
    }
    
    var defaultArguments: [String] {
        get {
            switch self {
            case.createAndCheckoutNewBranch: return ["checkout", "-b"]
            case .deleteBranch: return ["branch", "-d"]
            }
        }
    }
}

func demo1() {
    GitCommand.createAndCheckoutNewBranch.execute(with: ["new-branch-name"])
    GitCommand.deleteBranch.execute(with: ["some-old-branch"])
}

Example 2:

struct FileOperationCommand: AnyShellCommand {
    var command: String
}

func demo2() {
    let cDCommand = FileOperationCommand(command: "cd")

    let folderName = "new-folder"
    FileOperationCommand(command: "mkdir").execute(with: [folderName], onSuccess: { _ in
        cDCommand.execute(with: [folderName])
    }, onFailure: { _ in
        print("Failed to create new folder.")
    })
}

Installation

Using SwiftPM

In Package.swift file, define under dependencies:

.package(url: "https://github.com/DIY-Team/RunsShellCommand", from: "0.0.1")

dependency name: RunsShellCommand

GitHub

link
Stars: 1
Last commit: 1 week ago

Ad: Job Offers

iOS Software Engineer @ Perry Street Software
Perry Street Software is Jack’d and SCRUFF. We are two of the world’s largest gay, bi, trans and queer social dating apps on iOS and Android. Our brands reach more than 20 million members worldwide so members can connect, meet and express themselves on a platform that prioritizes privacy and security. We invest heavily into SwiftUI and using Swift Packages to modularize the codebase.

Swiftpack is being maintained by Petr Pavlik | @ptrpavlik | @swiftpackco | API