Skip to content

Commit

Permalink
Add ability to run program from WhiskyCmd
Browse files Browse the repository at this point in the history
  • Loading branch information
IsaacMarovitz committed Jan 12, 2024
1 parent 5522c55 commit 969d69e
Show file tree
Hide file tree
Showing 3 changed files with 27 additions and 9 deletions.
4 changes: 0 additions & 4 deletions Whisky.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -20,7 +20,6 @@
6E355E5829D78249002D83BE /* ConfigView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E355E5729D78249002D83BE /* ConfigView.swift */; };
6E355E5A29D782B2002D83BE /* ProgramsView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E355E5929D782B2002D83BE /* ProgramsView.swift */; };
6E355E5E29D7D85D002D83BE /* ProgramView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E355E5D29D7D85D002D83BE /* ProgramView.swift */; };
6E355E6029D7D8BD002D83BE /* Program+Extensions.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E355E5F29D7D8BD002D83BE /* Program+Extensions.swift */; };
6E40495629CCA19C006E3F1B /* WhiskyApp.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E40495529CCA19C006E3F1B /* WhiskyApp.swift */; };
6E40495829CCA19C006E3F1B /* ContentView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6E40495729CCA19C006E3F1B /* ContentView.swift */; };
6E40495A29CCA19C006E3F1B /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 6E40495929CCA19C006E3F1B /* Assets.xcassets */; };
Expand Down Expand Up @@ -118,7 +117,6 @@
6E355E5729D78249002D83BE /* ConfigView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConfigView.swift; sourceTree = "<group>"; };
6E355E5929D782B2002D83BE /* ProgramsView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramsView.swift; sourceTree = "<group>"; };
6E355E5D29D7D85D002D83BE /* ProgramView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ProgramView.swift; sourceTree = "<group>"; };
6E355E5F29D7D8BD002D83BE /* Program+Extensions.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "Program+Extensions.swift"; sourceTree = "<group>"; };
6E40495229CCA19C006E3F1B /* Whisky.app */ = {isa = PBXFileReference; explicitFileType = wrapper.application; includeInIndex = 0; path = Whisky.app; sourceTree = BUILT_PRODUCTS_DIR; };
6E40495529CCA19C006E3F1B /* WhiskyApp.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = WhiskyApp.swift; sourceTree = "<group>"; };
6E40495729CCA19C006E3F1B /* ContentView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ContentView.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -329,7 +327,6 @@
isa = PBXGroup;
children = (
6E40498229CCA91B006E3F1B /* Bottle+Extensions.swift */,
6E355E5F29D7D8BD002D83BE /* Program+Extensions.swift */,
);
path = Models;
sourceTree = "<group>";
Expand Down Expand Up @@ -602,7 +599,6 @@
6E2B25C12B0E20F50084A67A /* PinAddView.swift in Sources */,
6E49E0212AECB7DB00009CAC /* SettingsView.swift in Sources */,
6E7C07C02AAF570100F6E66B /* FileOpenView.swift in Sources */,
6E355E6029D7D8BD002D83BE /* Program+Extensions.swift in Sources */,
6E6C0CF22A419A6800356232 /* WelcomeView.swift in Sources */,
6E40498129CCA8B0006E3F1B /* BottleView.swift in Sources */,
6E355E5E29D7D85D002D83BE /* ProgramView.swift in Sources */,
Expand Down
25 changes: 24 additions & 1 deletion WhiskyCmd/Main.swift
Original file line number Diff line number Diff line change
Expand Up @@ -32,7 +32,8 @@ struct Whisky: ParsableCommand {
Add.self,
// Export.self,
Delete.self,
Remove.self
Remove.self,
Run.self
/*Install.self,
Uninstall.self*/])
}
Expand Down Expand Up @@ -156,6 +157,28 @@ extension Whisky {
}
}

struct Run: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Run a program with Whisky.")

@Argument var bottleName: String
@Argument var path: String
@Argument var args: [String] = []

mutating func run() throws {
var bottlesList = BottleData()
let bottles = bottlesList.loadBottles()

guard let bottle = bottles.first(where: { $0.settings.name == bottleName }) else {
print("A bottle with that name doesn't exist.")
return
}

let url = URL(fileURLWithPath: path)
let program = Program(url: url, bottle: bottle)
program.runInTerminal()
}
}

struct Install: ParsableCommand {
static var configuration = CommandConfiguration(abstract: "Install Whisky dependencies.")

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -18,11 +18,10 @@

import Foundation
import AppKit
import WhiskyKit
import os.log

extension Program {
func run() {
public func run() {
if NSEvent.modifierFlags.contains(.shift) {
self.runInTerminal()
} else {
Expand All @@ -47,11 +46,11 @@ extension Program {
}
}

func generateTerminalCommand() -> String {
public func generateTerminalCommand() -> String {
return Wine.generateRunCommand(bottle: bottle, args: settings.arguments, environment: generateEnvironment())
}

func runInTerminal() {
public func runInTerminal() {
let wineCmd = generateTerminalCommand().replacingOccurrences(of: "\\", with: "\\\\")

let script = """
Expand Down

0 comments on commit 969d69e

Please sign in to comment.