-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathmain.swift
68 lines (58 loc) · 1.71 KB
/
main.swift
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// Copyright (C) 2023 Devexperts LLC. All rights reserved.
// This Source Code Form is subject to the terms of the Mozilla Public License, v. 2.0.
// If a copy of the MPL was not distributed with this file, You can obtain one at http://mozilla.org/MPL/2.0/.
//
import Foundation
let commands: [ToolsCommand] = [PerfTestTool(),
ConnectTool(),
LatencyTestTool(),
DumpTool(),
QdsTool(),
HelpTool()]
func getCommand(_ cmd: String) -> ToolsCommand? {
let cmd = cmd.lowercased()
return commands.first { command in
command.cmd.lowercased() == cmd
}
}
func getCommandsDecription() -> String {
let maxSize = (commands.max { cmd1, cmd2 in
cmd1.cmd.count < cmd2.cmd.count
}?.cmd.count ?? 0) + 4
let descriptions = commands.compactMap { cmd in
if cmd.isTools {
let spaces = maxSize - cmd.cmd.count
return " \(cmd.cmd + String(repeating: " ", count: spaces)): \(cmd.shortDescription)"
} else {
return nil
}
}.joined(separator: "\n")
return descriptions
}
func printGlobalHelp() {
print(
"""
A collection of useful utilities that use the dxFeed API.
Usage:
Tools <tool> [...]
Where:
\(getCommandsDecription())
"""
)
}
if ProcessInfo.processInfo.arguments.count > 1 {
let command = ProcessInfo.processInfo.arguments[1]
switch command {
case "Help":
printGlobalHelp()
default:
if let toolsCmd = getCommand(command) {
toolsCmd.execute()
} else {
printGlobalHelp()
}
}
} else {
printGlobalHelp()
}