mirror of
https://github.com/nextcloud/desktop.git
synced 2025-08-15 23:32:13 +00:00
Move functions of mac crafter into different files
Signed-off-by: Claudio Cambra <claudio.cambra@nextcloud.com>
This commit is contained in:

committed by
Claudio Cambra

parent
01eba19d8d
commit
1bc7054fab
60
admin/osx/mac-crafter/Sources/Utils/Shell.swift
Normal file
60
admin/osx/mac-crafter/Sources/Utils/Shell.swift
Normal file
@ -0,0 +1,60 @@
|
||||
/*
|
||||
* Copyright (C) 2024 by Claudio Cambra <claudio.cambra@nextcloud.com>
|
||||
*
|
||||
* This program is free software; you can redistribute it and/or modify
|
||||
* it under the terms of the GNU General Public License as published by
|
||||
* the Free Software Foundation; either version 2 of the License, or
|
||||
* (at your option) any later version.
|
||||
*
|
||||
* This program is distributed in the hope that it will be useful, but
|
||||
* WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
|
||||
* or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
|
||||
* for more details.
|
||||
*/
|
||||
|
||||
import Foundation
|
||||
|
||||
@discardableResult
|
||||
func run(
|
||||
_ launchPath: String,
|
||||
_ args: [String],
|
||||
env: [String: String]? = nil,
|
||||
quiet: Bool = false
|
||||
) -> Int32 {
|
||||
let task = Process()
|
||||
task.launchPath = launchPath
|
||||
task.arguments = args
|
||||
|
||||
if let env,
|
||||
let combinedEnv = task.environment?.merging(env, uniquingKeysWith: { (_, new) in new })
|
||||
{
|
||||
task.environment = combinedEnv
|
||||
}
|
||||
|
||||
if quiet {
|
||||
task.standardOutput = nil
|
||||
task.standardError = nil
|
||||
}
|
||||
|
||||
task.launch()
|
||||
task.waitUntilExit()
|
||||
return task.terminationStatus
|
||||
}
|
||||
|
||||
func run(
|
||||
_ launchPath: String,
|
||||
_ args: String...,
|
||||
env: [String: String]? = nil,
|
||||
quiet: Bool = false
|
||||
) -> Int32 {
|
||||
return run(launchPath, args, env: env, quiet: quiet)
|
||||
}
|
||||
|
||||
@discardableResult
|
||||
func shell(_ commands: String..., env: [String: String]? = nil, quiet: Bool = false) -> Int32 {
|
||||
return run("/bin/zsh", ["-c"] + commands, env: env, quiet: quiet)
|
||||
}
|
||||
|
||||
func commandExists(_ command: String) -> Bool {
|
||||
return run("/usr/bin/type", command, quiet: true) == 0
|
||||
}
|
Reference in New Issue
Block a user