Skip to content

Commit

Permalink
change arg parser
Browse files Browse the repository at this point in the history
  • Loading branch information
kosyloa committed Oct 20, 2023
1 parent c6b7f4d commit 6b94df8
Show file tree
Hide file tree
Showing 16 changed files with 171 additions and 160 deletions.
12 changes: 4 additions & 8 deletions DXFeedFramework.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -189,7 +189,7 @@
646D19E22A3C994000C82315 /* DXFTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646D19E02A3C970700C82315 /* DXFTimer.swift */; };
646D19E32A3C994100C82315 /* DXFTimer.swift in Sources */ = {isa = PBXBuildFile; fileRef = 646D19E02A3C970700C82315 /* DXFTimer.swift */; };
647426A82ABC7F5E0012F793 /* ConnectEventListener.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647426A62ABC7F080012F793 /* ConnectEventListener.swift */; };
647426AD2ABC85F20012F793 /* ArgumentParser.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647426AC2ABC85F20012F793 /* ArgumentParser.swift */; };
647426AD2ABC85F20012F793 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647426AC2ABC85F20012F793 /* Arguments.swift */; };
647426AF2ABC93900012F793 /* EventCode+String.swift in Sources */ = {isa = PBXBuildFile; fileRef = 647426AE2ABC93900012F793 /* EventCode+String.swift */; };
6479BC2B2A4F35A300A3D404 /* QuoteView.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6479BC2A2A4F35A300A3D404 /* QuoteView.swift */; };
6486B9582AD00BDC00D8D5FA /* Summary.swift in Sources */ = {isa = PBXBuildFile; fileRef = 6486B9572AD00BDC00D8D5FA /* Summary.swift */; };
Expand Down Expand Up @@ -315,7 +315,6 @@
64D8BB452A39BB730071BC88 /* Main.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 64D8BB432A39BB730071BC88 /* Main.storyboard */; };
64D8BB472A39BB740071BC88 /* Assets.xcassets in Resources */ = {isa = PBXBuildFile; fileRef = 64D8BB462A39BB740071BC88 /* Assets.xcassets */; };
64D8BB4A2A39BB740071BC88 /* LaunchScreen.storyboard in Resources */ = {isa = PBXBuildFile; fileRef = 64D8BB482A39BB740071BC88 /* LaunchScreen.storyboard */; };
64D8C9522AE17739009E4799 /* Arguments.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64D8C9512AE17739009E4799 /* Arguments.swift */; };
64DA26B62AA1EF47005B1757 /* DXProfileIterator.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B52AA1EF47005B1757 /* DXProfileIterator.swift */; };
64DA26B82AA20095005B1757 /* NativeInstrumentProfileConnection.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B72AA20095005B1757 /* NativeInstrumentProfileConnection.swift */; };
64DA26BA2AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift in Sources */ = {isa = PBXBuildFile; fileRef = 64DA26B92AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift */; };
Expand Down Expand Up @@ -652,7 +651,7 @@
6469F8D22A3B401700846831 /* Colors.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Colors.swift; sourceTree = "<group>"; };
646D19E02A3C970700C82315 /* DXFTimer.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXFTimer.swift; sourceTree = "<group>"; };
647426A62ABC7F080012F793 /* ConnectEventListener.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ConnectEventListener.swift; sourceTree = "<group>"; };
647426AC2ABC85F20012F793 /* ArgumentParser.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = ArgumentParser.swift; sourceTree = "<group>"; };
647426AC2ABC85F20012F793 /* Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arguments.swift; sourceTree = "<group>"; };
647426AE2ABC93900012F793 /* EventCode+String.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = "EventCode+String.swift"; sourceTree = "<group>"; };
6479BC2A2A4F35A300A3D404 /* QuoteView.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = QuoteView.swift; sourceTree = "<group>"; };
6486B9572AD00BDC00D8D5FA /* Summary.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Summary.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -780,7 +779,6 @@
64D8BB462A39BB740071BC88 /* Assets.xcassets */ = {isa = PBXFileReference; lastKnownFileType = folder.assetcatalog; path = Assets.xcassets; sourceTree = "<group>"; };
64D8BB492A39BB740071BC88 /* Base */ = {isa = PBXFileReference; lastKnownFileType = file.storyboard; name = Base; path = Base.lproj/LaunchScreen.storyboard; sourceTree = "<group>"; };
64D8BB4B2A39BB740071BC88 /* Info.plist */ = {isa = PBXFileReference; lastKnownFileType = text.plist.xml; path = Info.plist; sourceTree = "<group>"; };
64D8C9512AE17739009E4799 /* Arguments.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = Arguments.swift; sourceTree = "<group>"; };
64DA26B52AA1EF47005B1757 /* DXProfileIterator.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXProfileIterator.swift; sourceTree = "<group>"; };
64DA26B72AA20095005B1757 /* NativeInstrumentProfileConnection.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = NativeInstrumentProfileConnection.swift; sourceTree = "<group>"; };
64DA26B92AA20AAA005B1757 /* DXInstrumentProfileConnectionState.swift */ = {isa = PBXFileReference; lastKnownFileType = sourcecode.swift; path = DXInstrumentProfileConnectionState.swift; sourceTree = "<group>"; };
Expand Down Expand Up @@ -933,8 +931,7 @@
children = (
64148B6E2ABB5C4A0063110E /* PerfTestCL.entitlements */,
64148B662ABB5C320063110E /* main.swift */,
64D8C9512AE17739009E4799 /* Arguments.swift */,
647426AC2ABC85F20012F793 /* ArgumentParser.swift */,
647426AC2ABC85F20012F793 /* Arguments.swift */,
647426A62ABC7F080012F793 /* ConnectEventListener.swift */,
645BE8532AC3229D0028243D /* ToolsCommand.swift */,
641BDD572AC71CCE00236B78 /* LatencyTestCommand.swift */,
Expand Down Expand Up @@ -1980,7 +1977,6 @@
isa = PBXSourcesBuildPhase;
buildActionMask = 2147483647;
files = (
64D8C9522AE17739009E4799 /* Arguments.swift in Sources */,
648BD56D2AC56A04004A3A95 /* SubscriptionUtils.swift in Sources */,
648BD56B2AC4576F004A3A95 /* HelpCommand.swift in Sources */,
649282E82AD54919008F0F04 /* ScheduleUtils.swift in Sources */,
Expand All @@ -2000,7 +1996,7 @@
647426A82ABC7F5E0012F793 /* ConnectEventListener.swift in Sources */,
644FE5CE2AC1EC1500580E3A /* TimeInterval+Ext.swift in Sources */,
64148B672ABB5C320063110E /* main.swift in Sources */,
647426AD2ABC85F20012F793 /* ArgumentParser.swift in Sources */,
647426AD2ABC85F20012F793 /* Arguments.swift in Sources */,
64098F4E2ACD73920020D741 /* PerfTestEventListener.swift in Sources */,
641BDD592AC7215200236B78 /* LatencyDiagnostic.swift in Sources */,
648BD5692AC450D6004A3A95 /* ConnectCommand.swift in Sources */,
Expand Down
10 changes: 3 additions & 7 deletions DXFeedFramework.xcodeproj/xcshareddata/xcschemes/Tools.xcscheme
Original file line number Diff line number Diff line change
Expand Up @@ -30,7 +30,7 @@
shouldAutocreateTestPlan = "YES">
</TestAction>
<LaunchAction
buildConfiguration = "Debug"
buildConfiguration = "Release"
selectedDebuggerIdentifier = "Xcode.DebuggerFoundation.Debugger.LLDB"
selectedLauncherIdentifier = "Xcode.DebuggerFoundation.Launcher.LLDB"
launchStyle = "0"
Expand Down Expand Up @@ -72,15 +72,11 @@
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect mddqa.in.devexperts.com:7400 Candle AAPL{=d} 20230201Z"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = "Connect mddqa.in.devexperts.com:7400 OptionSale AAPL"
argument = "Connect demo.dxfeed.com:7300 quote AAPL,IBM"
isEnabled = "NO">
</CommandLineArgument>
<CommandLineArgument
argument = " Dump demo.dxfeed.com:7300 timeandsale AAPL,IBM,ETH/USD:GDAX -t test_tape_ios.txt[format=text] -p dxfeed.wildcard.enable=true,one_more_prop=abc"
argument = " Dump localhost:6666 timeandsale,candle YQKNT -p dxfeed.wildcard.enable=true,one_more_prop=abc -t test_tape_ios.txt[format=text] -q"
isEnabled = "YES">
</CommandLineArgument>
<CommandLineArgument
Expand Down
10 changes: 10 additions & 0 deletions DXFeedFramework/Api/Osub/TimeSeriesSubscriptionSymbol.swift
Original file line number Diff line number Diff line change
Expand Up @@ -37,6 +37,16 @@ public class TimeSeriesSubscriptionSymbol: IndexedEventSubscriptionSymbol<AnyHas
self.init(symbol: symbol, fromTime: Long(date.timeIntervalSince1970) * 1000)
}

/// Initializes a new instance of the ``TimeSeriesSubscriptionSymbol`` class
/// with a specified event symbol and from date
///
/// - Parameters:
/// - symbol: The event ``Symbol``
/// - date: Date. Just for easing initialization with date object
convenience public init(symbol: Symbol, date: Date) {
self.init(symbol: symbol.stringValue, fromTime: Long(date.timeIntervalSince1970) * 1000)
}

static func == (lhs: TimeSeriesSubscriptionSymbol, rhs: TimeSeriesSubscriptionSymbol) -> Bool {
return lhs === rhs || lhs.symbol == rhs.symbol
}
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Events/Market/Extra/OrderSource.swift
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public class OrderSource: IndexedEventSource {
&& (name != OrderSource.decodeName(identifier: identifier)) {
throw ArgumentException.exception("id does not match name")
}
default: break
default: break
}
// Flag FullOrderBook requires that source must be publishable.
if (pubFlags & OrderSource.fullOrderBook) != 0 &&
Expand Down
2 changes: 1 addition & 1 deletion DXFeedFramework/Native/Endpoint/NativeEndpoint.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ class NativeEndpoint {
internal init(_ native: UnsafeMutablePointer<dxfg_endpoint_t>) {
self.endpoint = native
}

func getNativeFeed() -> NativeFeed? {
return self.feed
}
Expand Down
30 changes: 0 additions & 30 deletions Samples/PerfTestCL/ArgumentParser.swift

This file was deleted.

63 changes: 46 additions & 17 deletions Samples/PerfTestCL/Arguments.swift
Original file line number Diff line number Diff line change
@@ -1,24 +1,21 @@
//
// Arguments.swift
// Tools
// ArgumentParser.swift
// PerfTestCL
//
// Created by Aleksey Kosylo on 19.10.23.
// Created by Aleksey Kosylo on 21.09.23.
//

import Foundation
import DXFeedFramework

class Arguments {

let arguments: [String]
let symbolPosition: Int
enum ArgumentParserException: Error {
case error(message: String)
}

init(arguments: [String], symbolPosition: Int) {
self.arguments = arguments
self.symbolPosition = symbolPosition
}
class Arguments {
private let arguments: [String]

lazy var properties: [String: 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
Expand All @@ -33,22 +30,55 @@ class Arguments {
return properties
}()

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

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

func parseSymbols() -> [String] {
let symbols = arguments[symbolPosition]
public lazy var time: String? = {
if arguments.count > 4 {
return arguments[4]
} else {
return nil
}
}()

init(_ cmd: [String], requiredNumberOfArguments: Int) throws {
print("Parse \(cmd) to \(requiredNumberOfArguments) arguments")

if cmd.count - 1 < requiredNumberOfArguments {
throw ArgumentParserException.error(message:
"""
Cmd \(cmd) contains not enough \(cmd.count - 1) arguments. Expected \(requiredNumberOfArguments)
""")
}
// 0 Arg is path to executed app
self.arguments = Array(cmd[1..<cmd.count])
}

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

public var count: Int {
arguments.count
}

public func parseSymbols(at index: Int) -> [Symbol] {
let symbols = arguments[index]
if symbols.lowercased() == "all" {
return [WildcardSymbol.all]
}

var symbolsList = [String]()
func addSymbol(str: String) {
if str.hasPrefix("ipf[") && str.hasSuffix("]") {
Expand Down Expand Up @@ -85,7 +115,6 @@ class Arguments {
tempSrting.append(character)
}
}

addSymbol(str: tempSrting)
return symbolsList
}
Expand Down
28 changes: 11 additions & 17 deletions Samples/PerfTestCL/ConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,6 @@ class ConnectCommand: ToolsCommand {
Connect
=======
"address" argument parsing error. Insufficient parameters.
Usage:
Connect <address> <types> <symbols> [<time>]
Expand All @@ -43,28 +41,24 @@ Where:

var subscription = Subscription()

func execute() {
var arguments: [String]!
private lazy var arguments: Arguments = {
do {
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4)
let arguments = try Arguments(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4)
return arguments
} catch {
print(fullDescription)
fatalError()
}
let address = arguments[1]
let types = arguments[2]
}()

var time: String?
if arguments.count > 4 {
time = arguments[4]
}
let argumentsObj = Arguments(arguments: arguments, symbolPosition: 3)
let symbolsList = argumentsObj.parseSymbols()
func execute() {
let listener = ConnectEventListener()
subscription.createSubscription(address: address,
symbols: symbolsList,
types: types,
subscription.createSubscription(address: arguments[1],
symbols: arguments.parseSymbols(at: 3),
types: arguments[2],
listener: listener,
time: time)
properties: arguments.properties,
time: arguments.time)

// Print till input new line
_ = readLine()
Expand Down
24 changes: 12 additions & 12 deletions Samples/PerfTestCL/DumpCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -19,7 +19,7 @@ class DumpCommand: ToolsCommand {
Enforces a streaming contract for subscription. A wildcard enabled by default.
This was designed to receive data from a file.
Usage: Dump <address> <types> <symbols> [<options>]
Where:
<address> is a URL to Schedule API defaults file
<types> is comma-separated list of dxfeed event types ({eventTypeNames}).
Expand All @@ -31,29 +31,29 @@ class DumpCommand: ToolsCommand {
var publisher: DXPublisher?
var isQuite = false

func execute() {
var arguments: [String]!
private lazy var arguments: Arguments = {
do {
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4)
let arguments = try Arguments(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 4)
return arguments
} catch {
print(fullDescription)
fatalError()
}
}()

func execute() {
let address = arguments[1]
let types = arguments[2]
let argumentsObj = Arguments(arguments: arguments, symbolPosition: 3)
let symbols = argumentsObj.parseSymbols()
let symbols = arguments.parseSymbols(at: 3)

var tapeFile = argumentsObj.tape
isQuite = arguments.isQuite

isQuite = argumentsObj.isQuite

var properties = argumentsObj.properties
do {
let inputEndpoint = try DXEndpoint
.builder()
.withRole(.streamFeed)
.withProperty(DXEndpoint.Property.wildcardEnable.rawValue, "true")
.withProperties(properties)
.withProperties(arguments.properties)
.withName("DumpTool")
.build()

Expand All @@ -63,7 +63,7 @@ class DumpCommand: ToolsCommand {
let subscription = try inputEndpoint.getFeed()?.createSubscription(eventTypes)
var outputEndpoint: DXEndpoint?

if let tapeFile = tapeFile {
if let tapeFile = arguments.tape {
outputEndpoint = try DXEndpoint
.builder()
.withRole(.publisher)
Expand Down
10 changes: 7 additions & 3 deletions Samples/PerfTestCL/IpfConnectCommand.swift
Original file line number Diff line number Diff line change
Expand Up @@ -28,13 +28,17 @@ class IpfConnectCommand: ToolsCommand {
sample: DXFeedIpfConnect TimeAndSale sample.ipf.zip
"""

func execute() {
var arguments: [String]!
private lazy var arguments: Arguments = {
do {
arguments = try ArgumentParser().parse(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 2)
let arguments = try Arguments(ProcessInfo.processInfo.arguments, requiredNumberOfArguments: 2)
return arguments
} catch {
print(fullDescription)
fatalError()
}
}()

func execute() {
let eventType = arguments[1]
let ipfFile = arguments[2]
try? SystemProperty.setProperty(DXEndpoint.Property.address.rawValue, "demo.dxfeed.com:7300")
Expand Down
Loading

0 comments on commit 6b94df8

Please sign in to comment.