Skip to content
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
8 changes: 8 additions & 0 deletions Sources/AppBundle/command/impl/ListModesCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,14 @@ struct ListModesCommand: Command {
func run(_ env: CmdEnv, _ io: CmdIo) -> Bool {
if args.current {
return io.out(activeMode ?? mainModeId)
} else if args.json {
let modeNames: [String] = config.modes.map { $0.key }
return switch JSONEncoder.aeroSpaceDefault.encodeToString(modeNames).map(Result.success)
?? .failure("Can't encode '\(modeNames)' to JSON")
{
case .success(let json): io.out(json)
case .failure(let msg): io.err(msg)
}
} else {
let modeNames: [String] = config.modes.map { $0.key }
return io.out(modeNames)
Expand Down
1 change: 1 addition & 0 deletions Sources/AppBundleTests/command/ListModesTest.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,5 +6,6 @@ final class ListModesTest: XCTestCase {
func testParseListModesCommand() {
testParseCommandSucc("list-modes", ListModesCmdArgs(rawArgs: []))
testParseCommandSucc("list-modes --current", ListModesCmdArgs(rawArgs: []).copy(\.current, true))
testParseCommandSucc("list-modes --json", ListModesCmdArgs(rawArgs: []).copy(\.json, true))
}
}
2 changes: 2 additions & 0 deletions Sources/Common/cmdArgs/impl/ListModesCmdArgs.swift
Original file line number Diff line number Diff line change
Expand Up @@ -9,13 +9,15 @@ public struct ListModesCmdArgs: CmdArgs {
help: list_modes_help_generated,
options: [
"--current": trueBoolFlag(\.current),
"--json": trueBoolFlag(\.json),
],
arguments: []
)

public var windowId: UInt32? // unused
public var workspaceName: WorkspaceName? // unused
public var current: Bool = false
public var json: Bool = false
}

public func parseListModesCmdArgs(_ args: [String]) -> ParsedCmd<ListModesCmdArgs> {
Expand Down
Loading