Skip to content

Commit df2f514

Browse files
authored
Merge pull request #10 from daneov/exit_on_failing_command
Exit on failing command
2 parents 5ac9523 + 567b118 commit df2f514

File tree

2 files changed

+17
-14
lines changed

2 files changed

+17
-14
lines changed

Sources/Komondor/Commands/runner.swift

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -38,15 +38,17 @@ public func runner(logger _: Logger, args: [String]) throws {
3838
try commands.forEach { command in
3939
print("> \(command)")
4040
// Simple is fine for now
41-
try shellOut(to: command)
42-
41+
print(try shellOut(to: command))
4342
// Ideal:
4443
// Store STDOUT and STDERR, and only show it if it fails
4544
// Show a stepper like system of all commands
4645
}
46+
} catch let error as ShellOutError {
47+
print(error.message)
48+
print(error.output)
49+
exit(error.terminationStatus)
4750
} catch {
48-
guard let error = error as? ShellOutError else { return }
49-
print(error.message) // Prints STDERR
50-
print(error.output) // Prints STDOUT
51+
print(error)
52+
exit(1)
5153
}
5254
}

Sources/Komondor/main.swift

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,15 +10,7 @@ logger.debug("Setting up .git-hooks for Komondor (v\(KomondorVersion))")
1010

1111
let cliLength = ProcessInfo.processInfo.arguments.count
1212

13-
if cliLength > 1 {
14-
let task = CommandLine.arguments[1]
15-
if task == "install" {
16-
try install(logger: logger)
17-
} else if task == "run" {
18-
let runnerArgs = Array(CommandLine.arguments.dropFirst().dropFirst())
19-
try runner(logger: logger, args: runnerArgs)
20-
}
21-
} else {
13+
guard cliLength > 1 else {
2214
print("""
2315
Welcome to Komondor, it has 2 commands:
2416
@@ -27,4 +19,13 @@ if cliLength > 1 {
2719
2820
Docs are available at: https://github.com/orta/Komondor
2921
""")
22+
exit(0)
23+
}
24+
25+
let task = CommandLine.arguments[1]
26+
if task == "install" {
27+
try install(logger: logger)
28+
} else if task == "run" {
29+
let runnerArgs = Array(CommandLine.arguments.dropFirst().dropFirst())
30+
try runner(logger: logger, args: runnerArgs)
3031
}

0 commit comments

Comments
 (0)