I have a number of small command line tools made over time, and I'm thinking of combining them into one command line tool.
It's not a project as yet, but just a concept I'm playing around with, so there's no code base as yet which I can post.
But some thing like this below for the main.swift file.
And a number of swift files in the project for the different tools, like this below.
My question is, how would I declare the "toolType" variable ?
And of what class type should it be ?
And what class type should the different tools "Tool1", "Tool2", "Tool3" be declared as, or class inherited from ?
Ive tried changing the different tools 1 to 3 as inherited from "NSObject" and "Any" but neither work with the above code.
As stated above, this is not a project with a name or code base yet, other than the numerous small command line tools already made.
But in trying the toolbox concept above, Ive stumbled across the first problem, and need some guidance on how to implement the above.
The final goal would be to type from the terminal like this.
Thanks for any help
Regards Mark
It's not a project as yet, but just a concept I'm playing around with, so there's no code base as yet which I can post.
But some thing like this below for the main.swift file.
Swift:
//main.swift
import Foundation
func run() {
var toolType: Any
let arguments = Array(CommandLine.arguments)
if arguments.count == 0 {
print("Error: No tool type parameter entered")
exit(EXIT_FAILURE)
} else {
let argument = arguments[0]
switch argument {
case "Tool1": toolType = Tool1() // ERROR: won't allow this
case "Tool2": toolType = Tool2() // ERROR: won't allow this
case "Tool3": toolType = Tool3() // ERROR: won't allow this
default: print("Error: Unknown tool type parameter entered")
exit(EXIT_FAILURE)
}
print(toolType.name()) // ERROR: Value of type Any has no member 'name'
exit(EXIT_SUCCESS)
}
}
run()
And a number of swift files in the project for the different tools, like this below.
Swift:
//Tool1.swift
class Tool1 {
func name() -> String {
return "Tool1"
}
}
//Tool2.swift
class Tool2 {
func name() -> String {
return "Tool2"
}
}
//Tool3.swift
class Tool3 {
func name() -> String {
return "Tool3"
}
}
My question is, how would I declare the "toolType" variable ?
And of what class type should it be ?
And what class type should the different tools "Tool1", "Tool2", "Tool3" be declared as, or class inherited from ?
Ive tried changing the different tools 1 to 3 as inherited from "NSObject" and "Any" but neither work with the above code.
As stated above, this is not a project with a name or code base yet, other than the numerous small command line tools already made.
But in trying the toolbox concept above, Ive stumbled across the first problem, and need some guidance on how to implement the above.
The final goal would be to type from the terminal like this.
Bash:
toolbox tool1 <commands>
Thanks for any help
Regards Mark