Skip to content

Commit

Permalink
Removed usage of ArgumentParser since it is overhead to use it in suc…
Browse files Browse the repository at this point in the history
…h small tools. Added own arguments parsing instead.
  • Loading branch information
IhorShevchuk committed Apr 9, 2024
1 parent ecc04d4 commit ff15abb
Show file tree
Hide file tree
Showing 4 changed files with 53 additions and 31 deletions.
3 changes: 0 additions & 3 deletions Package.swift
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,6 @@ let package = Package(
targets: ["RHVoiceSwift"])
],
dependencies: [
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.3.1")
],
targets: [
.target(
Expand Down Expand Up @@ -182,7 +181,6 @@ let package = Package(
.executableTarget(
name: "RHVoiceSwiftSample",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser"),
.target(name: "RHVoiceSwift")
],
path: "Sources/RHVoiceSwiftSample",
Expand All @@ -199,7 +197,6 @@ let package = Package(
.executableTarget(
name: "PackDataExecutable",
dependencies: [
.product(name: "ArgumentParser", package: "swift-argument-parser")
],
path: "Sources/Plugins/PackDataExecutable"
),
Expand Down

This file was deleted.

60 changes: 50 additions & 10 deletions Sources/Plugins/PackDataExecutable/PackDataExecutable.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,22 +6,62 @@
// Copyright (C) 2022 Olga Yakovleva <olga@rhvoice.org>

import Foundation
import ArgumentParser

@main
struct PackDataExecutable: ParsableCommand {
struct PackDataExecutable {

@Option(help: "Input containing the data files")
var input: String
private enum PackDataError: Error {
case runtimeError(String)
}

/// Input containing the data files
private var input: String

/// Directory containing the output files
private var output: String

@Option(help: "Directory containing the output files")
var output: String
/// list of languages that should copied")
private var languages: String

@Option(help: "list of languages that should copied")
var languages: String
/// List of voices that should copied
private var voices: String

@Option(help: "list of voices that should copied")
var voices: String
static func main() throws {
let arguments = CommandLine.arguments
var input: String?
var output: String?
var languages: String?
var voices: String?

for (index, argument) in arguments.enumerated() {
switch argument {
case "--input":
input = arguments[index + 1]
case "--output":
output = arguments[index + 1]
case "--languages":
languages = arguments[index + 1]
case "--voices":
voices = arguments[index + 1]
default:
break
}
}

guard let input,
let output,
let languages,
let voices else {
throw PackDataError.runtimeError("Not enough arguments!")
}

let executable = PackDataExecutable(input: input,
output: output,
languages: languages,
voices: voices)

try executable.run()
}

func run() throws {
do {
Expand Down
7 changes: 3 additions & 4 deletions Sources/RHVoiceSwiftSample/RHVoiceSwiftSample.swift
Original file line number Diff line number Diff line change
Expand Up @@ -6,13 +6,12 @@
//

import Foundation
import ArgumentParser
import RHVoiceSwift

@main
struct PackDataExecutable: ParsableCommand {
struct PackDataExecutable {

var dataPath: String {
static var dataPath: String {
let fileUrl = URL(fileURLWithPath: #file)
.deletingLastPathComponent()
.deletingLastPathComponent()
Expand All @@ -21,7 +20,7 @@ struct PackDataExecutable: ParsableCommand {
return fileUrl.path + "/RHVoice/RHVoice/data"
}

func run() throws {
static func main() throws {
var params = RHVoiceSwift.RHSpeechSynthesizer.Params.default

params.dataPath = dataPath
Expand Down

0 comments on commit ff15abb

Please sign in to comment.