swift-argument-parser
swift-argument-parser copied to clipboard
It should be simpler to support piping input
ArgumentParser version: 1.1.2.
Swift version:
swift-driver version: 1.45.2 Apple Swift version 5.6.1 (swiftlang-5.6.0.323.66 clang-1316.0.20.12)
Target: arm64-apple-macosx12.0
Checklist
- [ ] If possible, I've reproduced the issue using the
mainbranch of this package - [x] I've searched for existing GitHub issues
Steps to Reproduce
a simple argument parser that could take an array of input
@main
struct Main: ParsableCommand {
@Argument
var path: [String]
func run() throws {}
}
compile this and run it with pipeline echo **/*.jpg | .build/arm64-apple-macosx/debug/main
it seems that the stdout is not pass as stdin
Expected behavior
the stdout from lhs is passed to rhs
Actual behavior
Describe or copy/paste the behavior you observe.
What's not working?
A shell piping stdout of one process to stdin of another process doesn't have any impact on the arguments passed to the second process.
There are argument parser libraries for other languages that do support mapping a single argument to either a provide file or stdin if no file is provided, but that doesn't seem to be related to what you might be asking about. It sorta sounds like you are asking for the library, when given no arguments, to parse all of stdin and map that to arguments? I don't think I've seen that feature in any argument parsing library for any language.
Oh i miss understand about argument parser as also able to parse stdin
I thought piping stdin is same with passing an argument to the executable
@wendyliga Thanks for the feedback! We’ve had a few requests for being able to automatically populate an argument with stdin, so I think it’s worth looking at more. I’m going to convert this to an enhancement request 👍🏻
@natecook1000 thank you, appreciate it
@wendyliga Thanks for the feedback! We’ve had a few requests for being able to automatically populate an argument with stdin, so I think it’s worth looking at more. I’m going to convert this to an enhancement request 👍🏻
Just a thought - maybe an async sequence? If building a pipeline took the amount of data coming can be infinite.
I was just working on a project where this really would have been useful! Perhaps something like @Argument(takeFromStandardInput: true) var input: String