Skip to content

Commit

Permalink
fix parse time arguments
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 24, 2023
1 parent e0a1248 commit 6b87d05
Show file tree
Hide file tree
Showing 4 changed files with 20 additions and 21 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -64,7 +64,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "ScheduleSample schedule.zip sample.ipf.zip AAPL 2012-05-26-14:15:00"
argument = "ScheduleSample schedule.zip sample.ipf.zip -f AAPL 2012-05-26-14:15:00"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
Expand All @@ -76,7 +76,7 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect demo.dxfeed.com:7300 quote AAPL,IBM"
argument = "Connect demo.dxfeed.com:7300 quote AAPL -f 2012-05-26-14:15:00"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
Expand Down
31 changes: 15 additions & 16 deletions Samples/PerfTestCL/Arguments.swift
Original file line number Diff line number Diff line change
Expand Up @@ -13,12 +13,12 @@ enum ArgumentParserException: Error {
}

class Arguments {
private let arguments: [String]
private let allParameters: [String]

public lazy var properties: [String: String] = {
var properties = [String: String]()
if let propIndex = arguments.firstIndex(of: "-p") {
arguments[propIndex + 1].split(separator: ",").forEach { substring in
if let propIndex = allParameters.firstIndex(of: "-p") {
allParameters[propIndex + 1].split(separator: ",").forEach { substring in
let prop = substring.split(separator: "=")
if prop.count == 2 {
properties[String(prop.first!)] = String(prop.last!)
Expand All @@ -31,25 +31,24 @@ class Arguments {
}()

public lazy var isQuite: Bool = {
if let isQuiteIndex = arguments.firstIndex(of: "-q") {
if let isQuiteIndex = allParameters.firstIndex(of: "-q") {
return true
}
return false
}()

public lazy var tape: String? = {
if let tapeIndex = arguments.firstIndex(of: "-t") {
return arguments[tapeIndex + 1]
if let tapeIndex = allParameters.firstIndex(of: "-t") {
return allParameters[tapeIndex + 1]
}
return nil
}()

public lazy var time: String? = {
if arguments.count > 4 {
return arguments[4]
} else {
return nil
if let tapeIndex = allParameters.firstIndex(of: "-f") {
return allParameters[tapeIndex + 1]
}
return nil
}()

init(_ cmd: [String], requiredNumberOfArguments: Int) throws {
Expand All @@ -62,28 +61,28 @@ Cmd \(cmd) contains not enough \(cmd.count - 1) arguments. Expected \(requiredNu
""")
}
// 0 Arg is path to executed app
self.arguments = Array(cmd[1..<cmd.count])
self.allParameters = Array(cmd[1..<cmd.count])
}

public subscript(index: Int) -> String {
arguments[index]
allParameters[index]
}

public var count: Int {
arguments.count
allParameters.count
}

public func parseTypes(at index: Int) -> [EventCode] {
if arguments[2] == "all" {
if allParameters[2] == "all" {
return EventCode.allCases
}
return arguments[2].split(separator: ",").compactMap { str in
return allParameters[2].split(separator: ",").compactMap { str in
return EventCode(string: String(str))
}
}

public func parseSymbols(at index: Int) -> [Symbol] {
let symbols = arguments[index]
let symbols = allParameters[index]
if symbols.lowercased() == "all" {
return [WildcardSymbol.all]
}
Expand Down
2 changes: 1 addition & 1 deletion Samples/PerfTestCL/ConnectTool.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ Connect
=======
Usage:
Connect <address> <types> <symbols> [<time>]
Connect <address> <types> <symbols> [-f <time>]
Where:
address - The address to connect to retrieve data (remote host or local tape file).
Expand Down
4 changes: 2 additions & 2 deletions Samples/PerfTestCL/ScheduleSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ class ScheduleSample: ToolsCommand {
A sample program that demonstrates different use cases of Schedule API.
Usage:
usage: ScheduleSample <defaults> <profiles> <symbol> [time]
usage: ScheduleSample <defaults> <profiles> <symbol> [-f time]
Where:
<defaults> is a URL to Schedule API defaults file
<profiles> is a URL to IPF file
<symbol> is a ticker symbol used for sample
[time] is a time used for sample in a format yyyy-MM-dd-HH:mm:ss
[-f time] is a time used for sample in a format yyyy-MM-dd-HH:mm:ss
sample: ScheduleSample schedule.properties.zip sample.ipf.zip IBM 2011-05-26-14:15:00
Expand Down

0 comments on commit 6b87d05

Please sign in to comment.