mxcl / Path.swift

Delightful, robust, cross-platform and chainable file-pathing functions.
The Unlicense
946 stars 36 forks source link

Add conformances to support Swift ArgumentParser? #88

Open JetForMe opened 2 years ago

JetForMe commented 2 years ago

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.

JetForMe commented 2 years ago

Oh oops never mind, ExpressibleByArgument is part of ArgumentParser, not Swift.

mxcl commented 2 years ago

In general: happy to accept PRs for additions that make sense