Skip to content

Custom argument separator chars #11

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

Closed
wants to merge 2 commits into from
Closed

Conversation

Grynn
Copy link

@Grynn Grynn commented May 3, 2018

This PR updates split to accept an array of optional chars to treat as argument separators.

This allows parsing of strings like
a,b,c,d ==> [ 'a','b','c','d' ]
"a,b",c, d" ==> [ 'a,b','c','d' ]

Usage:
\Clue\Arguments\split($commandLine); //Same as before
\Clue\Arguments\split($commandLine, [ "," ]); //Now possible

Grynn added 2 commits May 3, 2018 19:02
PHPUnit 6.x onwards namespaces PHPUnit_Framework_TestCase
@clue
Copy link
Owner

clue commented May 3, 2018

Hi @Grynn, thank you for taking the time to file this PR! 👍

Unfortunately, the PR does not contain any documentation or tests, so it's a bit unclear what you're trying to achieve from the snippet you've posted.

May I ask you provide a simple gist of what you're trying to achieve? Thanks!

@Grynn
Copy link
Author

Grynn commented May 3, 2018

Fair point, I really should have updated the README.

I was trying to use Clue\Argument\split() as a means of splitting a string into "words" for an Alfred workflow.

The idea is that I type stuff like $something = [ "a", "b", "c" ]; quite often and it's very annoying to have to quote all the words individually. I was hoping to save keystrokes by typing something like

cmd + space #launch alfred
qw word, word, word #run alfred workflow, which use Clue\Argument

and get "word", "word", "word" copied to my clipboard. (Note words are now quoted!)

I just want to be able to split a string into words, using separators other the whitespace chars you've pre-defined. In particular I want to be able to treat "," and ";" as whitespace. Obviously this will not be general, but many people may want to customize what word separator chars to use ... hence the extension to split() such that it can take an optional argument, which is a list of word separator chars.

@clue
Copy link
Owner

clue commented May 3, 2018

Thank you for the clarification! I'm not opposed to adding support for this here, but I'd like to make sure that this is within scope of this project's API.

As an alternative, it looks like you're not really trying to parse a "command line", so maybe using something like http://php.net/manual/en/function.str-getcsv.php might be an option for your use case?

@clue
Copy link
Owner

clue commented May 3, 2018

As a side note: I've just addressed the unrelated Travis build errors via #12.

@clue
Copy link
Owner

clue commented Dec 7, 2020

I'm closing this for now as it hasn't received any input in a while and I believe this has been answered. Please come back with more details if this problem persists and we can always reopen this 👍

@clue clue closed this Dec 7, 2020
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants