Skip to content

Commit

Permalink
parseRawCmdArgs -> parseSpecificCmdArgs
Browse files Browse the repository at this point in the history
  • Loading branch information
nikitabobko committed Sep 21, 2024
1 parent 2aa961e commit 5d58c02
Show file tree
Hide file tree
Showing 21 changed files with 22 additions and 23 deletions.
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/MacosNativeFullscreen.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@ public struct MacosNativeFullscreenCmdArgs: CmdArgs {
}

public func parseMacosNativeFullscreenCmdArgs(_ args: [String]) -> ParsedCmd<MacosNativeFullscreenCmdArgs> {
parseRawCmdArgs(MacosNativeFullscreenCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(MacosNativeFullscreenCmdArgs(rawArgs: args), args)
.filter("--fail-if-noop requires 'on' or 'off' argument") { $0.failIfNoop.implies($0.toggle == .on || $0.toggle == .off) }
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -23,5 +23,5 @@ public struct CloseAllWindowsButCurrentCmdArgs: CmdArgs {
}

public func parseCloseAllWindowsButCurrentCmdArgs(_ args: [String]) -> ParsedCmd<CloseAllWindowsButCurrentCmdArgs> {
parseRawCmdArgs(CloseAllWindowsButCurrentCmdArgs(rawArgs: .init(args)), args)
parseSpecificCmdArgs(CloseAllWindowsButCurrentCmdArgs(rawArgs: .init(args)), args)
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/ConfigCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -55,7 +55,7 @@ public extension ConfigCmdArgs {
}

public func parseConfigCmdArgs(_ args: [String]) -> ParsedCmd<ConfigCmdArgs> {
parseRawCmdArgs(ConfigCmdArgs(rawArgs: .init(args)), args)
parseSpecificCmdArgs(ConfigCmdArgs(rawArgs: .init(args)), args)
.flatMap { raw in
var conflicting: Set<String> = []
if raw.keyNameToGet != nil { conflicting.insert("--get") }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/EnableCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct EnableCmdArgs: CmdArgs {
}

public func parseEnableCmdArgs(_ args: [String]) -> ParsedCmd<EnableCmdArgs> {
return parseRawCmdArgs(EnableCmdArgs(rawArgs: args), args)
return parseSpecificCmdArgs(EnableCmdArgs(rawArgs: args), args)
.filterNot("--fail-if-noop is incompatible with 'toggle' argument") { $0.targetState.val == .toggle && $0.failIfNoop }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/FocusCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -96,7 +96,7 @@ public extension FocusCmdArgs {
}

public func parseFocusCmdArgs(_ args: [String]) -> ParsedCmd<FocusCmdArgs> {
return parseRawCmdArgs(FocusCmdArgs(rawArgs: args), args)
return parseSpecificCmdArgs(FocusCmdArgs(rawArgs: args), args)
.flatMap { (raw: FocusCmdArgs) -> ParsedCmd<FocusCmdArgs> in
raw.boundaries == .workspace && raw.boundariesAction == .wrapAroundAllMonitors
? .failure("\(raw.boundaries.rawValue) and \(raw.boundariesAction.rawValue) is an invalid combination of values")
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/FocusMonitorCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,7 @@ public struct FocusMonitorCmdArgs: CmdArgs {
}

public func parseFocusMonitorCmdArgs(_ args: [String]) -> ParsedCmd<FocusMonitorCmdArgs> {
parseRawCmdArgs(FocusMonitorCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(FocusMonitorCmdArgs(rawArgs: args), args)
.filter("--wrap-around is incompatible with <monitor-pattern> argument") { !$0.wrapAround || !$0.target.val.isPatterns }
}

Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/FullscreenCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ public struct FullscreenCmdArgs: CmdArgs {
}

public func parseFullscreenCmdArgs(_ args: [String]) -> ParsedCmd<FullscreenCmdArgs> {
parseRawCmdArgs(FullscreenCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(FullscreenCmdArgs(rawArgs: args), args)
.filterNot("--no-outer-gaps is incompatible with 'off' argument") { $0.toggle == .off && $0.noOuterGaps }
.filter("--fail-if-noop requires 'on' or 'off' argument") { $0.failIfNoop.implies($0.toggle == .on || $0.toggle == .off) }
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/JoinWithCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public struct JoinWithCmdArgs: CmdArgs {
}

public func parseJoinWithCmdArgs(_ args: [String]) -> ParsedCmd<JoinWithCmdArgs> {
parseRawCmdArgs(JoinWithCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(JoinWithCmdArgs(rawArgs: args), args)
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/LayoutCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ private func parseToggleBetween(arg: String, _ nextArgs: inout [String]) -> Pars
}

public func parseLayoutCmdArgs(_ args: [String]) -> ParsedCmd<LayoutCmdArgs> {
parseRawCmdArgs(LayoutCmdArgs(rawArgs: args), args).map {
parseSpecificCmdArgs(LayoutCmdArgs(rawArgs: args), args).map {
check(!$0.toggleBetween.val.isEmpty)
return $0
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/ListWindowsCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -56,7 +56,7 @@ public struct ListWindowsCmdArgs: CmdArgs {

public func parseRawListWindowsCmdArgs(_ args: [String]) -> ParsedCmd<ListWindowsCmdArgs> {
let args = args.map { $0 == "--app-id" ? "--app-bundle-id" : $0 } // Compatibility
return parseRawCmdArgs(ListWindowsCmdArgs(rawArgs: .init(args)), args)
return parseSpecificCmdArgs(ListWindowsCmdArgs(rawArgs: .init(args)), args)
.flatMap { raw in
var conflicting: OrderedSet<String> = []
if (raw.all) { conflicting.insert("--all", at: 0) }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/ListWorkspacesCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -46,7 +46,7 @@ public struct ListWorkspacesCmdArgs: CmdArgs {
}

public func parseListWorkspacesCmdArgs(_ args: [String]) -> ParsedCmd<ListWorkspacesCmdArgs> {
parseRawCmdArgs(ListWorkspacesCmdArgs(rawArgs: .init(args)), args)
parseSpecificCmdArgs(ListWorkspacesCmdArgs(rawArgs: .init(args)), args)
.flatMap { raw in
var conflicting: OrderedSet<String> = []
if raw.all { conflicting.append("--all") }
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/MoveCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,5 +25,5 @@ public struct MoveCmdArgs: CmdArgs {
}

public func parseMoveCmdArgs(_ args: [String]) -> ParsedCmd<MoveCmdArgs> {
parseRawCmdArgs(MoveCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(MoveCmdArgs(rawArgs: args), args)
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/MoveMouseCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ func parseMouseTarget(arg: String, nextArgs: inout [String]) -> Parsed<MouseTarg
}

public func parseMoveMouseCmdArgs(_ args: [String]) -> ParsedCmd<MoveMouseCmdArgs> {
parseRawCmdArgs(MoveMouseCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(MoveMouseCmdArgs(rawArgs: args), args)
.filter("--fail-if-noop is only compatible with window-lazy-center or monitor-lazy-center") {
$0.failIfNoop.implies($0.mouseTarget.val == .windowLazyCenter || $0.mouseTarget.val == .monitorLazyCenter)
}
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/MoveNodeToMonitorCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,6 @@ public struct MoveNodeToMonitorCmdArgs: CmdArgs {
}

public func parseMoveNodeToMonitorCmdArgs(_ args: [String]) -> ParsedCmd<MoveNodeToMonitorCmdArgs> {
parseRawCmdArgs(MoveNodeToMonitorCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(MoveNodeToMonitorCmdArgs(rawArgs: args), args)
.filter("--wrap-around is incompatible with <monitor-pattern> argument") { !$0.wrapAround || !$0.target.val.isPatterns }
}
Original file line number Diff line number Diff line change
Expand Up @@ -41,7 +41,7 @@ public extension MoveNodeToWorkspaceCmdArgs {
func implication(ifTrue: Bool, mustHold: @autoclosure () -> Bool) -> Bool { !ifTrue || mustHold() }

public func parseMoveNodeToWorkspaceCmdArgs(_ args: [String]) -> ParsedCmd<MoveNodeToWorkspaceCmdArgs> {
parseRawCmdArgs(MoveNodeToWorkspaceCmdArgs(rawArgs: .init(args)), args)
parseSpecificCmdArgs(MoveNodeToWorkspaceCmdArgs(rawArgs: .init(args)), args)
.filter("--wrapAround requires using (prev|next) argument") { ($0._wrapAround != nil).implies($0.target.val.isRelatve) }
.filterNot("--fail-if-noop is incompatible with (next|prev)") { $0.failIfNoop && $0.target.val.isRelatve }
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ public struct ResizeCmdArgs: CmdArgs {
}

public func parseResizeCmdArgs(_ args: [String]) -> ParsedCmd<ResizeCmdArgs> {
parseRawCmdArgs(ResizeCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(ResizeCmdArgs(rawArgs: args), args)
}

private func parseDimension(arg: String, nextArgs: inout [String]) -> Parsed<ResizeCmdArgs.Dimension> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/SplitCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ public struct SplitCmdArgs: CmdArgs {
}

public func parseSplitCmdArgs(_ args: [String]) -> ParsedCmd<SplitCmdArgs> {
parseRawCmdArgs(SplitCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(SplitCmdArgs(rawArgs: args), args)
}

private func parseSplitArg(arg: String, nextArgs: inout [String]) -> Parsed<SplitCmdArgs.SplitArg> {
Expand Down
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/TriggerBindingCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,6 @@ public extension TriggerBindingCmdArgs {
}

public func parseTriggerBindingCmdArgs(_ args: [String]) -> ParsedCmd<TriggerBindingCmdArgs> {
parseRawCmdArgs(TriggerBindingCmdArgs(rawArgs: .init(args)), args)
parseSpecificCmdArgs(TriggerBindingCmdArgs(rawArgs: .init(args)), args)
.filter("--mode flag is mandatory") { $0._mode != nil }
}
2 changes: 1 addition & 1 deletion Sources/Common/cmdArgs/impl/WorkspaceCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ public struct WorkspaceCmdArgs: CmdArgs {
}

public func parseWorkspaceCmdArgs(_ args: [String]) -> ParsedCmd<WorkspaceCmdArgs> {
parseRawCmdArgs(WorkspaceCmdArgs(rawArgs: args), args)
parseSpecificCmdArgs(WorkspaceCmdArgs(rawArgs: args), args)
.filter("--wrapAround requires using (prev|next) argument") { ($0._wrapAround != nil).implies($0.target.val.isRelatve) }
.filterNot("--auto-back-and-forth is incompatible with (next|prev)") { $0._autoBackAndForth != nil && $0.target.val.isRelatve }
.filterNot("--fail-if-noop is incompatible with (next|prev)") { $0.failIfNoop && $0.target.val.isRelatve }
Expand Down
Original file line number Diff line number Diff line change
@@ -1,6 +1,5 @@
// todo support conflicting options
// todo come up with better name for this function
public func parseRawCmdArgs<T: CmdArgs>(_ raw: T, _ args: [String]) -> ParsedCmd<T> {
public func parseSpecificCmdArgs<T: CmdArgs>(_ raw: T, _ args: [String]) -> ParsedCmd<T> {
var args = args
var raw = raw
var errors: [String] = []
Expand Down
4 changes: 2 additions & 2 deletions Sources/Common/cmdArgs/subcommandParsers.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,10 +19,10 @@ struct SubCommandParser<T: CmdArgs>: SubCommandParserProtocol {
}

init(_ raw: @escaping (EquatableNoop<[String]>) -> T) {
_parse = { args in parseRawCmdArgs(raw(.init(args)), args) }
_parse = { args in parseSpecificCmdArgs(raw(.init(args)), args) }
}

init(_ raw: @escaping ([String]) -> T) {
_parse = { args in parseRawCmdArgs(raw(args), args) }
_parse = { args in parseSpecificCmdArgs(raw(args), args) }
}
}

0 comments on commit 5d58c02

Please sign in to comment.