Skip to content

Commit

Permalink
Add --window-id and --workspace flags to all commands where it makes …
Browse files Browse the repository at this point in the history
…sense

#186
  • Loading branch information
nikitabobko committed Sep 23, 2024
1 parent 1000135 commit 47209bd
Show file tree
Hide file tree
Showing 33 changed files with 166 additions and 90 deletions.
4 changes: 2 additions & 2 deletions Sources/Cli/subcommandDescriptionsGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,9 +25,9 @@ let subcommandDescriptions = [
[" move-node-to-monitor", "Move window to monitor targeted by relative direction, by order, or by pattern"],
[" move-node-to-workspace", "Move the focused window to the specified workspace"],
[" move-workspace-to-monitor", "Move the focused workspace to the next or previous monitor"],
[" move", "Move the window in the given direction"],
[" move", "Move the focused window in the given direction"],
[" reload-config", "Reload currently active config"],
[" resize", "Resize the currently focused window"],
[" resize", "Resize the focused window"],
[" split", "Split focused window"],
[" trigger-binding", "Trigger AeroSpace binding as if it was pressed by user"],
[" workspace-back-and-forth", "Switch between the focused workspace and previously focused workspace back and forth"],
Expand Down
15 changes: 15 additions & 0 deletions Sources/Common/cmdArgs/ArgParser.swift
Original file line number Diff line number Diff line change
Expand Up @@ -25,6 +25,13 @@ public struct ArgParser<T: Copyable, K>: ArgParserProtocol {
public func hash(into hasher: inout Hasher) { hasher.combine(keyPath) }
}

public func optionalWindowIdFlag<T: CmdArgs>() -> ArgParser<T, UInt32?> {
ArgParser(\T.windowId, upcastArgParserFun(parseArgWithUInt32))
}
public func optionalWorkspaceFlag<T: CmdArgs>() -> ArgParser<T, WorkspaceName?> {
ArgParser(\T.workspaceName, upcastArgParserFun(parseArgWithWorkspaceName))
}

func newArgParser<T: Copyable, K>(
_ keyPath: WritableKeyPath<T, Lateinit<K>>,
_ parse: @escaping (String, inout [String]) -> Parsed<K>,
Expand Down Expand Up @@ -96,4 +103,12 @@ public func parseArgWithUInt32(arg: String, nextArgs: inout [String]) -> Parsed<
}
}

public func parseArgWithWorkspaceName(arg: String, nextArgs: inout [String]) -> Parsed<WorkspaceName> {
if let arg = nextArgs.nextNonFlagOrNil() {
WorkspaceName.parse(arg)
} else {
.failure("'\(arg)' must be followed by mandatory workspace name")
}
}

func upcastArgParserFun<T>(_ fun: @escaping ArgParserFun<T>) -> ArgParserFun<T?> { { fun($0, &$1).map { $0 } } }
4 changes: 3 additions & 1 deletion Sources/Common/cmdArgs/impl/BalanceSizesCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct BalanceSizesCmdArgs: CmdArgs {
kind: .balanceSizes,
allowInConfig: true,
help: balance_sizes_help_generated,
options: [:],
options: [
"--workspace": optionalWorkspaceFlag(),
],
arguments: []
)

Expand Down
1 change: 1 addition & 0 deletions Sources/Common/cmdArgs/impl/CloseCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct CloseCmdArgs: CmdArgs {
help: close_help_generated,
options: [
"--quit-if-last-window": trueBoolFlag(\.quitIfLastWindow),
"--window-id": optionalWindowIdFlag(),
],
arguments: []
)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct FlattenWorkspaceTreeCmdArgs: CmdArgs {
kind: .flattenWorkspaceTree,
allowInConfig: true,
help: flatten_workspace_tree_help_generated,
options: [:],
options: [
"--workspace": optionalWorkspaceFlag(),
],
arguments: []
)

Expand Down
1 change: 1 addition & 0 deletions Sources/Common/cmdArgs/impl/FullscreenCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public struct FullscreenCmdArgs: CmdArgs {
options: [
"--no-outer-gaps": trueBoolFlag(\.noOuterGaps),
"--fail-if-noop": trueBoolFlag(\.failIfNoop),
"--window-id": optionalWindowIdFlag(),
],
arguments: [ArgParser(\.toggle, parseToggleEnum)]
)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Common/cmdArgs/impl/LayoutCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct LayoutCmdArgs: CmdArgs {
kind: .layout,
allowInConfig: true,
help: layout_help_generated,
options: [:],
options: [
"--window-id": optionalWindowIdFlag(),
],
arguments: [newArgParser(\.toggleBetween, parseToggleBetween, mandatoryArgPlaceholder: LayoutDescription.unionLiteral)]
)

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct MacosNativeFullscreenCmdArgs: CmdArgs {
help: macos_native_fullscreen_help_generated,
options: [
"--fail-if-noop": trueBoolFlag(\.failIfNoop),
"--window-id": optionalWindowIdFlag(),
],
arguments: [ArgParser(\.toggle, parseToggleEnum)]
)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Common/cmdArgs/impl/MoveCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct MoveCmdArgs: CmdArgs {
kind: .move,
allowInConfig: true,
help: move_help_generated,
options: [:],
options: [
"--window-id": optionalWindowIdFlag(),
],
arguments: [newArgParser(\.direction, parseCardinalDirectionArg, mandatoryArgPlaceholder: CardinalDirection.unionLiteral)]
)

Expand Down
1 change: 1 addition & 0 deletions Sources/Common/cmdArgs/impl/MoveNodeToMonitorCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct MoveNodeToMonitorCmdArgs: CmdArgs {
help: move_node_to_monitor_help_generated,
options: [
"--wrap-around": trueBoolFlag(\.wrapAround),
"--window-id": optionalWindowIdFlag(),
],
arguments: [newArgParser(\.target, parseTarget, mandatoryArgPlaceholder: "(left|down|up|right|next|prev|<monitor-pattern>)")]
)
Expand Down
2 changes: 2 additions & 0 deletions Sources/Common/cmdArgs/impl/MoveNodeToWorkspaceCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ public struct MoveNodeToWorkspaceCmdArgs: CmdArgs {
options: [
"--wrap-around": optionalTrueBoolFlag(\._wrapAround),
"--fail-if-noop": trueBoolFlag(\.failIfNoop),
"--window-id": optionalWindowIdFlag(),
],
arguments: [newArgParser(\.target, parseWorkspaceTarget, mandatoryArgPlaceholder: workspaceTargetPlaceholder)]
)
Expand All @@ -32,4 +33,5 @@ public func parseMoveNodeToWorkspaceCmdArgs(_ args: [String]) -> ParsedCmd<MoveN
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 }
.filterNot("--window-id is incompatible with (next|prev)") { $0.windowId != nil && $0.target.val.isRelatve }
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@ public struct MoveWorkspaceToMonitorCmdArgs: CmdArgs {
help: move_workspace_to_monitor_help_generated,
options: [
"--wrap-around": trueBoolFlag(\.wrapAround),
"--workspace": optionalWorkspaceFlag(),
],
arguments: [newArgParser(\.target, parseMonitorTarget, mandatoryArgPlaceholder: "(next|prev)")]
)
Expand Down
4 changes: 3 additions & 1 deletion Sources/Common/cmdArgs/impl/ResizeCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct ResizeCmdArgs: CmdArgs {
kind: .resize,
allowInConfig: true,
help: resize_help_generated,
options: [:],
options: [
"--window-id": optionalWindowIdFlag(),
],
arguments: [
newArgParser(\.dimension, parseDimension, mandatoryArgPlaceholder: "(smart|width|height)"),
newArgParser(\.units, parseUnits, mandatoryArgPlaceholder: "[+|-]<number>"),
Expand Down
4 changes: 3 additions & 1 deletion Sources/Common/cmdArgs/impl/SplitCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,9 @@ public struct SplitCmdArgs: CmdArgs {
kind: .split,
allowInConfig: true,
help: split_help_generated,
options: [:],
options: [
"--window-id": optionalWindowIdFlag(),
],
arguments: [newArgParser(\.arg, parseSplitArg, mandatoryArgPlaceholder: SplitArg.unionLiteral)]
)

Expand Down
37 changes: 19 additions & 18 deletions Sources/Common/cmdHelpGenerated.swift
Original file line number Diff line number Diff line change
@@ -1,13 +1,13 @@
// FILE IS GENERATED BY generate.sh --all

let balance_sizes_help_generated = """
USAGE: balance-sizes [-h|--help]
USAGE: balance-sizes [-h|--help] [--workspace <workspace>]
"""
let close_all_windows_but_current_help_generated = """
USAGE: close-all-windows-but-current [-h|--help] [--quit-if-last-window]
"""
let close_help_generated = """
USAGE: close [-h|--help] [--quit-if-last-window]
USAGE: close [-h|--help] [--quit-if-last-window] [--window-id <window-id>]
"""
let config_help_generated = """
USAGE: config [-h|--help] --get <name> [--json] [--keys]
Expand All @@ -27,7 +27,7 @@ let exec_and_forget_help_generated = """
USAGE: exec-and-forget <bash-script>
"""
let flatten_workspace_tree_help_generated = """
USAGE: flatten-workspace-tree [-h|--help]
USAGE: flatten-workspace-tree [-h|--help] [--workspace <workspace>]
"""
let focus_back_and_forth_help_generated = """
USAGE: focus-back-and-forth [-h|--help]
Expand All @@ -45,15 +45,16 @@ let focus_help_generated = """
OR: focus [-h|--help] --dfs-index <dfs-index>
"""
let fullscreen_help_generated = """
USAGE: fullscreen [-h|--help] [--no-outer-gaps]
OR: fullscreen [-h|--help] on [--no-outer-gaps] [--fail-if-noop]
OR: fullscreen [-h|--help] off [--fail-if-noop]
USAGE: fullscreen [-h|--help] [--window-id <window-id>] [--no-outer-gaps]
OR: fullscreen [-h|--help] on [--window-id <window-id>] [--no-outer-gaps] [--fail-if-noop]
OR: fullscreen [-h|--help] off [--window-id <window-id>] [--fail-if-noop]
"""
let join_with_help_generated = """
USAGE: join-with [-h|--help] (left|down|up|right)
"""
let layout_help_generated = """
USAGE: layout [-h|--help] (h_tiles|v_tiles|h_accordion|v_accordion|tiles|accordion|horizontal|vertical|tiling|floating)...
USAGE: layout [-h|--help] [--window-id <window-id>]
(h_tiles|v_tiles|h_accordion|v_accordion|tiles|accordion|horizontal|vertical|tiling|floating)...
"""
let list_apps_help_generated = """
USAGE: list-apps [-h|--help] [--macos-native-hidden [no]] [--format <output-format>]
Expand All @@ -77,9 +78,9 @@ let list_workspaces_help_generated = """
OR: list-workspaces [-h|--help] --focused [--format <output-format>]
"""
let macos_native_fullscreen_help_generated = """
USAGE: macos-native-fullscreen [-h|--help]
OR: macos-native-fullscreen [-h|--help] [--fail-if-noop] on
OR: macos-native-fullscreen [-h|--help] [--fail-if-noop] off
USAGE: macos-native-fullscreen [-h|--help] [--window-id <window-id>]
OR: macos-native-fullscreen [-h|--help] [--window-id <window-id>] [--fail-if-noop] on
OR: macos-native-fullscreen [-h|--help] [--window-id <window-id>] [--fail-if-noop] off
"""
let macos_native_minimize_help_generated = """
USAGE: macos-native-minimize [-h|--help]
Expand All @@ -91,28 +92,28 @@ let move_mouse_help_generated = """
USAGE: move-mouse [-h|--help] [--fail-if-noop] <mouse-position>
"""
let move_node_to_monitor_help_generated = """
USAGE: move-node-to-monitor [-h|--help] [--wrap-around] (left|down|up|right)
OR: move-node-to-monitor [-h|--help] [--wrap-around] (next|prev)
OR: move-node-to-monitor [-h|--help] <monitor-pattern>...
USAGE: move-node-to-monitor [-h|--help] [--window-id <window-id>] [--wrap-around] (left|down|up|right)
OR: move-node-to-monitor [-h|--help] [--window-id <window-id>] [--wrap-around] (next|prev)
OR: move-node-to-monitor [-h|--help] [--window-id <window-id>] <monitor-pattern>...
"""
let move_node_to_workspace_help_generated = """
USAGE: move-node-to-workspace [-h|--help] [--wrap-around] (next|prev)
OR: move-node-to-workspace [-h|--help] [--fail-if-noop] <workspace-name>
OR: move-node-to-workspace [-h|--help] [--fail-if-noop] [--window-id <window-id>] <workspace-name>
"""
let move_workspace_to_monitor_help_generated = """
USAGE: move-workspace-to-monitor [-h|--help] [--wrap-around] (next|prev)
USAGE: move-workspace-to-monitor [-h|--help] [--workspace <workspace>] [--wrap-around] (next|prev)
"""
let move_help_generated = """
USAGE: move [-h|--help] (left|down|up|right)
USAGE: move [-h|--help] [--window-id <window-id>] (left|down|up|right)
"""
let reload_config_help_generated = """
USAGE: reload-config [-h|--help] [--no-gui] [--dry-run]
"""
let resize_help_generated = """
USAGE: resize [-h|--help] (smart|width|height) [+|-]<number>
USAGE: resize [-h|--help] [--window-id <window-id>] (smart|width|height) [+|-]<number>
"""
let split_help_generated = """
USAGE: split [-h|--help] (horizontal|vertical|opposite)
USAGE: split [-h|--help] [--window-id <window-id>] (horizontal|vertical|opposite)
"""
let trigger_binding_help_generated = """
USAGE: trigger-binding [-h|--help] <binding> --mode <mode-id>
Expand Down
11 changes: 7 additions & 4 deletions docs/aerospace-balance-sizes.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include::util/man-attributes.adoc[]
== Synopsis
[verse]
// tag::synopsis[]
aerospace balance-sizes [-h|--help]
aerospace balance-sizes [-h|--help] [--workspace <workspace>]

// end::synopsis[]

Expand All @@ -19,12 +19,15 @@ aerospace balance-sizes [-h|--help]
// tag::body[]
{manpurpose}

// end::body[]

// =========================================================== Options
include::util/conditional-options-header.adoc[]
include::./util/conditional-options-header.adoc[]

-h, --help:: Print help

--workspace <workspace>::
include::./util/workspace-flag-desc.adoc[]

// end::body[]

// =========================================================== Footer
include::util/man-footer.adoc[]
2 changes: 1 addition & 1 deletion docs/aerospace-close-all-windows-but-current.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -23,8 +23,8 @@ aerospace close-all-windows-but-current [-h|--help] [--quit-if-last-window]
include::util/conditional-options-header.adoc[]

-h, --help:: Print help

--quit-if-last-window:: Quit the apps instead of closing them if it's their last window

// end::body[]

// =========================================================== Footer
Expand Down
9 changes: 6 additions & 3 deletions docs/aerospace-close.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include::util/man-attributes.adoc[]
== Synopsis
[verse]
// tag::synopsis[]
aerospace close [-h|--help] [--quit-if-last-window]
aerospace close [-h|--help] [--quit-if-last-window] [--window-id <window-id>]

// end::synopsis[]

Expand All @@ -23,11 +23,14 @@ Normally, you don’t need to use this command, because macOS offers its own `cm
You might want to use the command from CLI for scripting purposes

// =========================================================== Options
include::util/conditional-options-header.adoc[]
include::./util/conditional-options-header.adoc[]

-h, --help:: Print help

--quit-if-last-window:: Quit the app instead of closing if it's the last window of the app

--window-id <window-id>::
include::./util/window-id-flag-desc.adoc[]

// end::body[]

// =========================================================== Footer
Expand Down
10 changes: 7 additions & 3 deletions docs/aerospace-flatten-workspace-tree.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,7 +9,7 @@ include::util/man-attributes.adoc[]
== Synopsis
[verse]
// tag::synopsis[]
aerospace flatten-workspace-tree [-h|--help]
aerospace flatten-workspace-tree [-h|--help] [--workspace <workspace>]

// end::synopsis[]

Expand All @@ -20,12 +20,16 @@ aerospace flatten-workspace-tree [-h|--help]
{manpurpose}

The command is useful when you messed up with your layout, and it's easier to "reset" it and start again.
// end::body[]

// =========================================================== Options
include::util/conditional-options-header.adoc[]
include::./util/conditional-options-header.adoc[]

-h, --help:: Print help

--workspace <workspace>::
include::./util/workspace-flag-desc.adoc[]

// end::body[]

// =========================================================== Footer
include::util/man-footer.adoc[]
4 changes: 2 additions & 2 deletions docs/aerospace-focus-monitor.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -22,13 +22,13 @@ aerospace focus-monitor [-h|--help] <monitor-pattern>...
{manpurpose}

// =========================================================== Options
include::util/conditional-options-header.adoc[]
include::./util/conditional-options-header.adoc[]

-h, --help:: Print help
--wrap-around:: Make it possible to wrap around focus

// =========================================================== Arguments
include::util/conditional-arguments-header.adoc[]
include::./util/conditional-arguments-header.adoc[]

(left|down|up|right)::
Focus monitor in direction relative to the focused monitor
Expand Down
14 changes: 8 additions & 6 deletions docs/aerospace-fullscreen.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -9,9 +9,9 @@ include::util/man-attributes.adoc[]
== Synopsis
[verse]
// tag::synopsis[]
aerospace fullscreen [-h|--help] [--no-outer-gaps]
aerospace fullscreen [-h|--help] on [--no-outer-gaps] [--fail-if-noop]
aerospace fullscreen [-h|--help] off [--fail-if-noop]
aerospace fullscreen [-h|--help] [--window-id <window-id>] [--no-outer-gaps]
aerospace fullscreen [-h|--help] on [--window-id <window-id>] [--no-outer-gaps] [--fail-if-noop]
aerospace fullscreen [-h|--help] off [--window-id <window-id>] [--fail-if-noop]

// end::synopsis[]

Expand All @@ -24,15 +24,17 @@ aerospace fullscreen [-h|--help] off [--fail-if-noop]
Switching to a different tiling window within the same workspace while the current focused window is in fullscreen mode results in the fullscreen window exiting fullscreen mode.

// =========================================================== Options
include::util/conditional-options-header.adoc[]
include::./util/conditional-options-header.adoc[]

-h, --help:: Print help

--no-outer-gaps:: Remove the outer gaps when in fullscreen mode
--fail-if-noop:: Exit with non-zero exit code if already fullscreen or already not fullscreen

--window-id <window-id>::
include::./util/window-id-flag-desc.adoc[]

// =========================================================== Arguments
include::util/conditional-arguments-header.adoc[]
include::./util/conditional-arguments-header.adoc[]

on, off::
`on` means enter fullscreen mode. `off` means exit fullscreen mode.
Expand Down
Loading

0 comments on commit 47209bd

Please sign in to comment.