swift-argument-parser icon indicating copy to clipboard operation
swift-argument-parser copied to clipboard

It should be simpler to support piping input

Open wendyliga opened this issue 3 years ago • 7 comments

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 main branch 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.

wendyliga avatar May 25 '22 11:05 wendyliga

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.

thomasvl avatar May 25 '22 15:05 thomasvl

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 avatar May 25 '22 23:05 wendyliga

@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 avatar Jun 01 '22 00:06 natecook1000

@natecook1000 thank you, appreciate it

wendyliga avatar Jun 01 '22 01:06 wendyliga

@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.

hassila avatar Jun 01 '22 05:06 hassila

I was just working on a project where this really would have been useful! Perhaps something like @Argument(takeFromStandardInput: true) var input: String

Samasaur1 avatar Sep 11 '22 20:09 Samasaur1