From b1bbd0c43a03bdd79bee5597268df07f315902a4 Mon Sep 17 00:00:00 2001 From: Bendik Solheim Date: Sun, 19 Jan 2025 09:53:49 +0100 Subject: [PATCH 1/4] Add new command list-modes --- Sources/AppBundle/command/cmdManifest.swift | 2 ++ .../command/impl/ListModesCommand.swift | 17 ++++++++++ .../Cli/subcommandDescriptionsGenerated.swift | 1 + Sources/Common/cmdArgs/cmdArgsManifest.swift | 3 ++ .../cmdArgs/impl/ListModesCmdArgs.swift | 23 +++++++++++++ Sources/Common/cmdHelpGenerated.swift | 3 ++ docs/aerospace-list-modes.adoc | 34 +++++++++++++++++++ 7 files changed, 83 insertions(+) create mode 100644 Sources/AppBundle/command/impl/ListModesCommand.swift create mode 100644 Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift create mode 100644 docs/aerospace-list-modes.adoc diff --git a/Sources/AppBundle/command/cmdManifest.swift b/Sources/AppBundle/command/cmdManifest.swift index 86da833f..0615a929 100644 --- a/Sources/AppBundle/command/cmdManifest.swift +++ b/Sources/AppBundle/command/cmdManifest.swift @@ -36,6 +36,8 @@ extension CmdArgs { command = ListAppsCommand(args: self as! ListAppsCmdArgs) case .listExecEnvVars: command = ListExecEnvVarsCommand(args: self as! ListExecEnvVarsCmdArgs) + case .listModes: + command = ListModesCommand(args: self as! ListModesCmdArgs) case .listMonitors: command = ListMonitorsCommand(args: self as! ListMonitorsCmdArgs) case .listWindows: diff --git a/Sources/AppBundle/command/impl/ListModesCommand.swift b/Sources/AppBundle/command/impl/ListModesCommand.swift new file mode 100644 index 00000000..82a017f9 --- /dev/null +++ b/Sources/AppBundle/command/impl/ListModesCommand.swift @@ -0,0 +1,17 @@ +import AppKit +import Common + +struct ListModesCommand: Command { + let args: ListModesCmdArgs + + func run(_ env: CmdEnv, _ io: CmdIo) -> Bool { + check(Thread.current.isMainThread) + + if args.current { + return io.out(activeMode ?? mainModeId) + } else { + let modeNames: [String] = config.modes.map { $0.key } + return io.out(modeNames) + } + } +} diff --git a/Sources/Cli/subcommandDescriptionsGenerated.swift b/Sources/Cli/subcommandDescriptionsGenerated.swift index b27b3d5e..b6a1997d 100644 --- a/Sources/Cli/subcommandDescriptionsGenerated.swift +++ b/Sources/Cli/subcommandDescriptionsGenerated.swift @@ -17,6 +17,7 @@ let subcommandDescriptions = [ [" layout", "Change layout of the focused window to the given layout"], [" list-apps", "Print the list of running applications that appears in the Dock and may have a user interface"], [" list-exec-env-vars", "List environment variables that exec-* commands and callbacks are run with"], + [" list-modes", "Print a list of modes currently specified in the configuration"], [" list-monitors", "Print monitors that satisfy conditions"], [" list-windows", "Print windows that satisfy conditions"], [" list-workspaces", "Print workspaces that satisfy conditions"], diff --git a/Sources/Common/cmdArgs/cmdArgsManifest.swift b/Sources/Common/cmdArgs/cmdArgsManifest.swift index 39c342b3..2befd72c 100644 --- a/Sources/Common/cmdArgs/cmdArgsManifest.swift +++ b/Sources/Common/cmdArgs/cmdArgsManifest.swift @@ -17,6 +17,7 @@ public enum CmdKind: String, CaseIterable, Equatable { case layout case listApps = "list-apps" case listExecEnvVars = "list-exec-env-vars" + case listModes = "list-modes" case listMonitors = "list-monitors" case listWindows = "list-windows" case listWorkspaces = "list-workspaces" @@ -76,6 +77,8 @@ func initSubcommands() -> [String: any SubCommandParserProtocol] { result[kind.rawValue] = SubCommandParser(parseListAppsCmdArgs) case .listExecEnvVars: result[kind.rawValue] = SubCommandParser(ListExecEnvVarsCmdArgs.init) + case .listModes: + result[kind.rawValue] = SubCommandParser(parseListModesCmdArgs) case .listMonitors: result[kind.rawValue] = SubCommandParser(parseListMonitorsCmdArgs) case .listWindows: diff --git a/Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift b/Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift new file mode 100644 index 00000000..fe3d38f5 --- /dev/null +++ b/Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift @@ -0,0 +1,23 @@ +public struct ListModesCmdArgs: CmdArgs { + public let rawArgs: EquatableNoop<[String]> + public init(rawArgs: [String]) { + self.rawArgs = .init(rawArgs) + } + public static var parser: CmdParser = cmdParser( + kind: .listModes, + allowInConfig: false, + help: list_modes_help_generated, + options: [ + "--current": trueBoolFlag(\.current), + ], + arguments: [] + ) + + public var windowId: UInt32? // unused + public var workspaceName: WorkspaceName? // unused + public var current: Bool = false +} + +public func parseListModesCmdArgs(_ args: [String]) -> ParsedCmd { + parseSpecificCmdArgs(ListModesCmdArgs(rawArgs: args), args) +} diff --git a/Sources/Common/cmdHelpGenerated.swift b/Sources/Common/cmdHelpGenerated.swift index 295327b2..8a06b7a8 100644 --- a/Sources/Common/cmdHelpGenerated.swift +++ b/Sources/Common/cmdHelpGenerated.swift @@ -63,6 +63,9 @@ let list_apps_help_generated = """ let list_exec_env_vars_help_generated = """ USAGE: list-exec-env-vars [-h|--help] """ +let list_modes_help_generated = """ + USAGE: list-modes [-h|--help] [--current] + """ let list_monitors_help_generated = """ USAGE: list-monitors [-h|--help] [--focused [no]] [--mouse [no]] [--format ] [--count] [--json] """ diff --git a/docs/aerospace-list-modes.adoc b/docs/aerospace-list-modes.adoc new file mode 100644 index 00000000..b36571a2 --- /dev/null +++ b/docs/aerospace-list-modes.adoc @@ -0,0 +1,34 @@ += aerospace-list-modes(1) +include::util/man-attributes.adoc[] +// tag::purpose[] +:manpurpose: Print a list of modes currently specified in the configuration +// end::purpose[] +:manname: aerospace-list-modes + +// =========================================================== Synopsis +== Synopsis +[verse] +// tag::synopsis[] +aerospace list-modes [-h|--help] [--current] + +// end::synopsis[] + +// =========================================================== Description +== Description + +// tag::body[] +{manpurpose} + +See xref:guide.adoc#binding-modes[the guide] for documentation about binding modes +// end::body[] + +// =========================================================== Options +include::util/conditional-options-header.adoc[] + +-h, --help:: Print help + +--current:: +Only print the currently active mode + +// =========================================================== Footer +include::util/man-footer.adoc[] From 5164312edc8798c2cad811b79b40cc75061d8560 Mon Sep 17 00:00:00 2001 From: Bendik Solheim Date: Sun, 19 Jan 2025 09:54:07 +0100 Subject: [PATCH 2/4] Add test for list-modes command --- Sources/AppBundleTests/command/ListModesTest.swift | 12 ++++++++++++ 1 file changed, 12 insertions(+) create mode 100644 Sources/AppBundleTests/command/ListModesTest.swift diff --git a/Sources/AppBundleTests/command/ListModesTest.swift b/Sources/AppBundleTests/command/ListModesTest.swift new file mode 100644 index 00000000..11d39406 --- /dev/null +++ b/Sources/AppBundleTests/command/ListModesTest.swift @@ -0,0 +1,12 @@ +@testable import AppBundle +import Common +import XCTest + +final class ListModesTest: XCTestCase { + override func setUpWithError() throws { setUpWorkspacesForTests() } + + func testParseListModesCommand() { + testParseCommandSucc("list-modes", ListModesCmdArgs(rawArgs: [])) + testParseCommandSucc("list-modes --current", ListModesCmdArgs(rawArgs: []).copy(\.current, true)) + } +} From dfc1b0cd9f2dc8cc8a737fa8a146a089c1411aae Mon Sep 17 00:00:00 2001 From: Bendik Solheim Date: Sun, 19 Jan 2025 09:54:26 +0100 Subject: [PATCH 3/4] Add list-modes command to "Query commands" docs --- docs/commands.adoc | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/docs/commands.adoc b/docs/commands.adoc index f010dbf7..479db12b 100644 --- a/docs/commands.adoc +++ b/docs/commands.adoc @@ -239,6 +239,13 @@ include::aerospace-list-exec-env-vars.adoc[tags=synopsis] include::aerospace-list-exec-env-vars.adoc[tags=purpose] include::aerospace-list-exec-env-vars.adoc[tags=body] +=== list-modes +---- +include::aerospace-list-modes.adoc[tags=synopsis] +---- +include::aerospace-list-modes.adoc[tags=purpose] +include::aerospace-list-modes.adoc[tags=body] + === list-monitors ---- include::aerospace-list-monitors.adoc[tags=synopsis] From eaf5a81780f7d5c272393f519c2c97cc4acb18be Mon Sep 17 00:00:00 2001 From: Bendik Solheim Date: Sun, 19 Jan 2025 09:54:51 +0100 Subject: [PATCH 4/4] Add list-modes command to grammar file --- grammar/commands-bnf-grammar.txt | 2 ++ 1 file changed, 2 insertions(+) diff --git a/grammar/commands-bnf-grammar.txt b/grammar/commands-bnf-grammar.txt index b0173735..ea9155eb 100644 --- a/grammar/commands-bnf-grammar.txt +++ b/grammar/commands-bnf-grammar.txt @@ -86,6 +86,8 @@ aerospace -h; | list-exec-env-vars + | list-modes [--current] + | list-monitors [--focused [no] | --mouse [no] | --format | --count | --json]... | list-windows [ | --format | --count | --json]...