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

Customize array flag functionality #17

Open
infalmo opened this issue Oct 18, 2020 · 5 comments
Open

Customize array flag functionality #17

infalmo opened this issue Oct 18, 2020 · 5 comments

Comments

@infalmo
Copy link

infalmo commented Oct 18, 2020

Take a program that takes input of the following form:

multidiff --input 1.in 2.in 3.in --output 1.out 2.out 3.out

Now, the flags can be achieved using .Flags().StringSlice(...) which would take the input in format:

multidiff --input=1.in,2.in,3.in --output=1.out,2.out,3.out

However, imagine there were many (say 100) matching input and output files. Using tab completion lists all files, but uses a space to seperate them (instead of a comma, that pflag uses).
So, my question is, is there any way to achieve the above, without writing platform dependent shell scripts?

@cornfeedhobo
Copy link
Owner

@infinitepr0 I can only think of specifying the flag multiple times

@infalmo
Copy link
Author

infalmo commented Dec 13, 2020

What about something like

multidiff --input-begin *.in --input-end --output-begin *.out --output-end

I don't think this is widely used, so I guess it would be better to not create a non-conventional method.

@cornfeedhobo
Copy link
Owner

@infinitepr0 For what it's worth. I'm still thinking about this. If I think of something elegant, I'll be sure to revisit this.

@hoshsadiq
Copy link

Fwiw the --flag value1 value2 and --flag value1,value2 isn't really used anywhere but in spf13/pflag. Usually arguments are either positional or flags, or flags followed by their value. In my opinion a stringslice should only accept --flag val1 --flag val2 (or its shorthand equivalent). The CSV option is especially painful as you cannot have a value with commas in it. E.g. let's say you're rebuilding packers var option (--var key=value), if value is allowed to have commas in it, it's harder to achieve this.

I've never come across a CLI tool that expects multiple inputs and multiple outputs. Take mv for example. It has unlimited source files/directories, but one target file/directory. Same with cp.

@cornfeedhobo
Copy link
Owner

cornfeedhobo commented Mar 13, 2021

@hoshsadiq I agree. This CSV parsing causing more trouble than it's worth. I'm not sure ripping it out would work out for the cobra users though. Might be worth investigating.

In fact, another issue was submitted upstream that relates to this.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants