Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Array arguments #101

Closed
liscio opened this issue Apr 8, 2019 · 7 comments
Closed

Array arguments #101

liscio opened this issue Apr 8, 2019 · 7 comments
Labels
duplicate This issue or pull request already exists enhancement New feature or request

Comments

@liscio
Copy link
Contributor

liscio commented Apr 8, 2019

I've been using Console for building some internal tools, and it's been going great so far. Thanks for separating it from vapor, and for the recent ConsoleKit changes!

Anyway, I was wondering today whether you folks considered allowing for an argument to be specified multiple times? For instance, say I have an input argument that can be specified multiple times. It'd be used like so:

my-command --input /path/to/input --input /path/to/other/input --output /path/to/output

Ideally, this would allow me to get an array of paths for the key "input" from a CommandContext.

Thoughts?

@calebkleveter
Copy link
Member

I like this. I'm wondering if maybe using a comma separated list might be better though?

my-command --input /path/to/input,/path/to/other/input --output /path/to/output

@liscio
Copy link
Contributor Author

liscio commented Apr 8, 2019

Is there a precedent for that usage? I can't think of one myself—especially one that plays nicely when used in bash scripts, etc.

For instance, xcodebuild uses the pattern I proposed to specify multiple localization languages (-exportLanguage), find allows you to specify many duplicated switches on the command line (like -or predicates), and it's also common to think of input files in this way. Think, cat fileA fileB fileC > bigFile, for instance.

@calebkleveter
Copy link
Member

I think it may be more common in the Python world? I haven't looked a whole lot. I'm fine going either way.

@KyleLeneau
Copy link
Contributor

Just to chime in, Python's Click library does it the way @liscio mentioned but they also have an optional guard in the form of nargs: https://click.palletsprojects.com/en/7.x/options/#multi-value-options

@tanner0101 tanner0101 added the enhancement New feature or request label Jan 21, 2020
@tanner0101
Copy link
Member

tanner0101 commented Jan 21, 2020

This seems like a worthwhile addition. I think we'd need a new property wrapper for it. Something like:

@Array(name: "input")
var inputs: [String]

@Array name should be bike-shedded as there's probably something better. Maybe @Options (with an s)?

@calebkleveter
Copy link
Member

You could also conform Array to LosslessStringConvertible.

@tanner0101 tanner0101 changed the title Array Arguments? Array arguments Mar 27, 2020
@gwynne gwynne added the duplicate This issue or pull request already exists label Aug 19, 2023
@gwynne
Copy link
Member

gwynne commented Aug 19, 2023

This is essentially superseded by #180

@gwynne gwynne closed this as not planned Won't fix, can't repro, duplicate, stale Aug 19, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
duplicate This issue or pull request already exists enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

5 participants