Skip to content

Commit f5fba68

Browse files
authored
README: Add instructions for pre-defined commands
1 parent a24c5eb commit f5fba68

File tree

1 file changed

+63
-1
lines changed

1 file changed

+63
-1
lines changed

README.md

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Even though you can accomplish most of the tasks you need to do in native Swift
77

88
## Usage
99

10-
Just call `shellOut()`, and specify what command you want to run, along with any arguments you want to pass:
10+
Just call `shellOut()`, and specify what command you want to run, along with any arguments you want to pass:
1111

1212
```swift
1313
let output = try shellOut(to: "echo", arguments: ["Hello world"])
@@ -32,6 +32,68 @@ do {
3232
}
3333
```
3434

35+
## Pre-defined commands
36+
37+
Another way to use ShellOut is by executing pre-defined commands, that enable you to easily perform common tasks without having to construct commands using strings. It also ships with a set of such pre-defined commands for common tasks, such as using Git, manipulating the file system and using tools like [Marathon](https://github.com/JohnSundell/Marathon), [CocoaPods](https://cocoapods.org) and [Fastlane](https://fastlane.tools).
38+
39+
### Use Git
40+
41+
```swift
42+
try shellOut(to: .gitInit())
43+
try shellOut(to: .gitClone(url: repositoryURL))
44+
try shellOut(to: .gitCommit(message: "A scripted commit!"))
45+
try shellOut(to: .gitPush())
46+
try shellOut(to: .gitPull(remote: "origin", branch: "release"))
47+
try shellOut(to: .gitSubmoduleUpdate())
48+
try shellOut(to: .gitCheckout(branch: "my-feature"))
49+
```
50+
51+
### Handle files, folders and symlinks
52+
53+
```swift
54+
try shellOut(to: .createFolder(named: "folder"))
55+
try shellOut(to: .createFile(named: "file", contents: "Hello world"))
56+
try shellOut(to: .moveFile(from: "path/a", to: "path/b"))
57+
try shellOut(to: .openFile(at: "Project.xcodeproj"))
58+
try shellOut(to: .readFile(at: "Podfile"))
59+
try shellOut(to: .createSymlink(to: "target", at: "link"))
60+
try shellOut(to: .expandSymlink(at: "link"))
61+
```
62+
63+
*For a more powerful and object-oriented way to handle Files & Folders in Swift, check out [Files](https://github.com/JohnSundell/Files)*
64+
65+
### Use [Marathon](https://github.com/JohnSundell/Marathon)
66+
67+
```swift
68+
try shellOut(to: .runMarathonScript(at: "~/scripts/MyScript", arguments: ["One", "Two"]))
69+
try shellOut(to: .updateMarathonPackages())
70+
```
71+
72+
### Use [The Swift Package Manager](https://github.com/apple/swift-package-manager)
73+
74+
```swift
75+
try shellOut(to: .createSwiftPackage(withType: .executable))
76+
try shellOut(to: .updateSwiftPackages())
77+
try shellOut(to: .generateSwiftPackageXcodeProject())
78+
try shellOut(to: .buildSwiftPackage())
79+
try shellOut(to: .testSwiftPackage())
80+
```
81+
82+
### Use [Fastlane](https://fastlane.tools)
83+
84+
```swift
85+
try shellOut(to: .runFastlane(usingLane: "appstore"))
86+
```
87+
88+
### Use [CocoaPods](https://cocoapods.org)
89+
90+
```swift
91+
try shellOut(to: .updateCocoaPods())
92+
try shellOut(to: .installCocoaPods())
93+
```
94+
95+
Don't see what you're looking for in the list above? You can easily define your own commands using `ShellOutCommand`. If you've made a command you think should be included among the built-in ones, feel free to [open a PR](https://github.com/JohnSundell/ShellOut/pull/new/master)!
96+
3597
## Installation
3698

3799
### For scripts

0 commit comments

Comments
 (0)