Path.swift
Path.swift copied to clipboard
Add conformances to support Swift ArgumentParser?
The Swift ArgumentParser library makes it easy to parse command-line arguments. I feel like it should be possible to directly provide a Path argument:
struct
Calculate : ParsableCommand
{
@Option(name: .shortAndLong, help: "Path to input word list, one per line")
var inputWordList: Path = Path.cwd/"wordlist.txt"
}
extension
Path : ExpressibleByArgument
{
public init?(argument: String) {
if let p = Path(argument)
{
self = p
}
else
{
return nil
}
}
}
but the ExpressibleByArgument conformance seems clunky to me.
Oh oops never mind, ExpressibleByArgument is part of ArgumentParser, not Swift.
In general: happy to accept PRs for additions that make sense