import ArgumentParser import Foundation struct SpaceFocusCommand: CLICommand { static let configuration = CommandConfiguration( commandName: "space-focus", abstract: String(localized: "Focus a native desktop using its Mission Control shortcut.", bundle: .module)) @OptionGroup var output: CLIOptions @Argument(help: ArgumentHelp(String(localized: "Desktop number, from 1 to 16.", bundle: .module))) var number: Int mutating func validate() throws { try validateDesktop(number) } var invocation: CLIInvocation { .engine("space-focus", args: [String(number)], json: output.json) } } struct WindowToSpaceCommand: CLICommand { static let configuration = CommandConfiguration( commandName: "window-to-space", abstract: String(localized: "Move the focused window to a native desktop.", bundle: .module)) @OptionGroup var output: CLIOptions @Argument(help: ArgumentHelp(String(localized: "Desktop number, from 1 to 16.", bundle: .module))) var number: Int @Flag( help: ArgumentHelp( String(localized: "Keep the destination desktop active after moving the window.", bundle: .module))) var follow = false mutating func validate() throws { try validateDesktop(number) } var invocation: CLIInvocation { .engine("window-to-space", args: [String(number)] + (follow ? ["--follow"] : []), json: output.json) } } struct WindowToAdjacentSpaceCommand: CLICommand { static var configuration: CommandConfiguration { CommandConfiguration(commandName: Action.name, abstract: Action.abstract) } @OptionGroup var output: CLIOptions @Flag( help: ArgumentHelp( String(localized: "Keep the destination desktop active after moving the window.", bundle: .module))) var follow = false var invocation: CLIInvocation { .engine(Action.name, args: follow ? ["--follow"] : [], json: output.json) } } enum SpaceNextShortcut: Shortcut { static let name = "space-next" static var abstract: String { String(localized: "Focus the next native Space.", bundle: .module) } } enum SpacePreviousShortcut: Shortcut { static let name = "space-previous" static var abstract: String { String(localized: "Focus the previous native Space.", bundle: .module) } } enum SpaceBackAndForthShortcut: Shortcut { static let name = "space-back-and-forth" static var abstract: String { String(localized: "Return to the last native desktop on this display.", bundle: .module) } } enum WindowToSpaceNextShortcut: Shortcut { static let name = "window-to-space-next" static var abstract: String { String(localized: "Move the focused window to the next native Space.", bundle: .module) } } enum WindowToSpacePreviousShortcut: Shortcut { static let name = "window-to-space-previous" static var abstract: String { String(localized: "Move the focused window to the previous native Space.", bundle: .module) } } private func validateDesktop(_ number: Int) throws { guard (1...16).contains(number) else { throw ValidationError(String(localized: "Choose a desktop number from 1 to 16.", bundle: .module)) } }