Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Implement list-modes command #1025

Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 2 additions & 0 deletions Sources/AppBundle/command/cmdManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
17 changes: 17 additions & 0 deletions Sources/AppBundle/command/impl/ListModesCommand.swift
Original file line number Diff line number Diff line change
@@ -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)
}
}
}
12 changes: 12 additions & 0 deletions Sources/AppBundleTests/command/ListModesTest.swift
Original file line number Diff line number Diff line change
@@ -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))
}
}
1 change: 1 addition & 0 deletions Sources/Cli/subcommandDescriptionsGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"],
Expand Down
3 changes: 3 additions & 0 deletions Sources/Common/cmdArgs/cmdArgsManifest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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"
Expand Down Expand Up @@ -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:
Expand Down
23 changes: 23 additions & 0 deletions Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift
Original file line number Diff line number Diff line change
@@ -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<Self> = 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<ListModesCmdArgs> {
parseSpecificCmdArgs(ListModesCmdArgs(rawArgs: args), args)
}
3 changes: 3 additions & 0 deletions Sources/Common/cmdHelpGenerated.swift
Original file line number Diff line number Diff line change
Expand Up @@ -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 <output-format>] [--count] [--json]
"""
Expand Down
34 changes: 34 additions & 0 deletions docs/aerospace-list-modes.adoc
Original file line number Diff line number Diff line change
@@ -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[]
7 changes: 7 additions & 0 deletions docs/commands.adoc
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
2 changes: 2 additions & 0 deletions grammar/commands-bnf-grammar.txt
Original file line number Diff line number Diff line change
Expand Up @@ -86,6 +86,8 @@ aerospace -h;

| list-exec-env-vars

| list-modes [--current]

| list-monitors [--focused [no] | --mouse [no] | --format <output_format> | --count | --json]...

| list-windows [<list_windows_filter_flag> | --format <output_format> | --count | --json]...
Expand Down
Loading