jjrscott

It should be simpler to support piping input

Swift Argument Parser:

Appreciate this issues is very old but here’s my solution for what it’s worth. I’m sure one could do the same for FileHandle and InputStream. One concern is the @retroactive keyword but I suspect that would go away if the code was folded into this project repo.

extension Data: @retroactive ExpressibleByArgument {
    public init?(argument: String) {
        if argument == "-" {
            self = FileHandle.standardInput.availableData
        } else if let url = URL(string: argument), let data = try? Data(contentsOf: url) {
            self = data
        } else if let data = try? Data(contentsOf: URL(fileURLWithPath: argument)) {
            self = data
        } else {
            return nil
        }
    }
}