Path.swift icon indicating copy to clipboard operation
Path.swift copied to clipboard

Add conformances to support Swift ArgumentParser?

Open JetForMe opened this issue 3 years ago • 2 comments

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 avatar Jan 07 '22 22:01 JetForMe

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

JetForMe avatar Jan 07 '22 22:01 JetForMe

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

mxcl avatar Jan 10 '22 15:01 mxcl