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

v2 feature: Comma separated slice flags #1134

Closed
3 tasks done
zemzale opened this issue May 5, 2020 · 21 comments · Fixed by #1582
Closed
3 tasks done

v2 feature: Comma separated slice flags #1134

zemzale opened this issue May 5, 2020 · 21 comments · Fixed by #1582
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request status/triage maintainers still need to look into this
Milestone

Comments

@zemzale
Copy link
Contributor

zemzale commented May 5, 2020

Checklist

  • Are you running the latest v2 release? The list of releases is here.
  • Did you check the manual for your release? The v2 manual is here
  • Did you perform a search about this feature? Here's the Github guide about searching.

What problem does this solve?

Solution description

  • Add option CommaSeparated to StringSliceFlag, IntSliceFlag, Int64SliceFlag and Float64SliceFlag that allows comma separation for these flags.
  • If this option is enabled we would split these values when Set is called on them.
  • It would default to false so it wouldn't break backwards compatibility.

Describe alternatives you've considered

Although this would be the simplest solution IMO as mentioned in #1118

it is absolutely possible to get this behavior for very customized CLIs by implementing the cli.Flag interface manually.

It could be implemented by adding new Flags that add this behavior.

@zemzale zemzale added area/v2 relates to / is being considered for v2 status/triage maintainers still need to look into this labels May 5, 2020
@saschagrunert
Copy link
Member

saschagrunert commented May 6, 2020

Sounds like a good feature, we could also make the separator configurable.

@vschettino
Copy link
Contributor

Do you guys need help on this one? I think I could open a PR to add this feature. Seems like it would solve #1097 as well, right?

@xordspar0
Copy link
Contributor

@vschettino If you're interested in working on this, you should go ahead and submit a PR! Any help is welcome.

@stale
Copy link

stale bot commented Dec 31, 2020

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Dec 31, 2020
@noerw
Copy link

noerw commented Jan 14, 2021

not stale

@stale
Copy link

stale bot commented Jan 14, 2021

This issue or PR has been bumped and is no longer marked as stale! Feel free to bump it again in the future, if it's still relevant.

@stale stale bot removed the status/stale stale due to the age of it's last update label Jan 14, 2021
@coilysiren
Copy link
Member

This sounds like a great idea 👍🏼 would love to see a PR for this

@Haransis
Copy link

Well if there is no PR opened yet on this, I will submit one.

@Haransis
Copy link

Actually, this PR #1241 does exactly that.
It does not use a CommaSeparated flag but it should not break backwards compatibility.

@stale
Copy link

stale bot commented Jul 13, 2021

This issue or PR has been automatically marked as stale because it has not had recent activity. Please add a comment bumping this if you're still interested in it's resolution! Thanks for your help, please let us know if you need anything else.

@stale stale bot added the status/stale stale due to the age of it's last update label Jul 13, 2021
@stale
Copy link

stale bot commented Aug 18, 2021

Closing this as it has become stale.

@stale stale bot closed this as completed Aug 18, 2021
@potuz
Copy link

potuz commented Nov 10, 2021

bumping this issue as is a very useful feature, with a PR (albeit unmantained)

@rliebz rliebz reopened this Nov 10, 2021
@meatballhat meatballhat added kind/feature describes a code enhancement / feature request and removed status/stale stale due to the age of it's last update labels Apr 21, 2022
@gaocegege
Copy link

Actually, this PR #1241 does exactly that. It does not use a CommaSeparated flag but it should not break backwards compatibility.

I am wondering how to disable it without the flag CommaSeparated. I upgraded the package from v1 to v2 and found it broken. Could we provide such a flag for customization?

@dearchap
Copy link
Contributor

dearchap commented Aug 1, 2022

v1 to v2 is expected to have breaking changes.

@feedmeapples
Copy link
Contributor

Actually, this PR #1241 does exactly that. It does not use a CommaSeparated flag but it should not break backwards compatibility.

I am wondering how to disable it without the flag CommaSeparated. I upgraded the package from v1 to v2 and found it broken. Could we provide such a flag for customization?

commas are normal especially when passing JSON as a value, ex

tctl workflow start --input '{ \"Concurrency\": 1, \"Count\": 1}'

I would like to send a PR adding CommaSeparated to

  • Slice flags. Default false to keep the current behavior working
  • App struct as an option to disable comma separation altogether so that the behavior is consistent throughout the app. Default true to keep the current behavior working

Any objections?

@dearchap
Copy link
Contributor

dearchap commented Oct 8, 2022 via email

@ina-stoyanova
Copy link

I am hitting an issue, where I want to pass in json to a StringSliceFlag, and seeing that urfave actually interprets that as separate flag values by default.

Example:

  • I want to be able to pass in
mycli --input 'MAP={ "key1" : "value1", "key2" : { "key3" : "value3" } }"'
  • and I want to be able to get back (I'm using printing to stdout here)
MAP={ "key1" : "value1" "key2" : { "key3" : "value3" } }"
  • Right now, I get:
MAP={ "key1" : "value1"      <---- this is treated as one value for the flag 
"key2" : { "key3" : "value3" } }"   <---- this is treated as another value for the flag 

Seems like @feedmeapples was hitting the exact same issue here. @feedmeapples did you ever get a chance to open a PR for that?

@dearchap
Copy link
Contributor

@ina-stoyanova PR #1546 has a fix for this. You can set the string slice separator to something else

@ina-stoyanova
Copy link

Oh, that's great to see @dearchap! I'll keep an eye out for the latest release in the next few days (I'm pretty sure I can use the branch name until then!)

That's great timing :) Thanks for everyone's effort that has gone into it before I jumped in here 🙏🙏🙏

@feedmeapples
Copy link
Contributor

@ina-stoyanova @dearchap added one more PR #1582 to actually allow disabling separator completely

This was referenced Nov 16, 2022
@ina-stoyanova
Copy link

thank you loads @feedmeapples and @dearchap! I'll update to the latest again as soon as I can :)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
area/v2 relates to / is being considered for v2 kind/feature describes a code enhancement / feature request status/triage maintainers still need to look into this
Projects
None yet
Development

Successfully merging a pull request may close this issue.